review askeet Day 2

DBでまず、何が必要かを考える。
askeetというのはデモサイトを見た限り、日本で言うところのOKwaveやY!知恵袋みたいなもの。
ということで必要なものを考えると

  • question (質問)
  • answer (答え)
  • user (ユーザー)
  • relevancy (妥当性)

となる…みたい。

schema.ymlを書く。

ということでデータベース設計を書きたいと思います。
前回、askeet通りにしたらえらいことになったのでschema.ymlを書きます。
場所: askeet2/config/schema.yml

propel:
  _attributes:      { noXsd: false, defaultIdMethod: none, package: lib.model }

  ask_question:
    _attributes:    { phpName: Question, idMethod: native }
    id:             { type: integer, required: true, primaryKey: true, autoIncrement: true }
    user_id:        { type: integer, foreignTable: ask_user, foreignReference: id }
    title:          { type: longvarchar }
    body:           { type: longvarchar }
    created_at:     ~
    updated_at:     ~

  ask_answer:
    _attributes:    { phpName: Answer, idMethod: native }
    id:             { type: integer, required: true, primaryKey: true, autoIncrement: true }
    question_id:    { type: integer, foreignTable: ask_question, foreignReference: id }
    user_id:        { type: integer, foreignTable: ask_user, foreignReference: id }
    body:           { type: longvarchar }
    created_at:     ~

  ask_user:
    _attributes:    { phpName: User, idMethod: native }
    id:             { type: integer, required: true, primaryKey: true, autoIncrement: true }
    nickname:       { type: varchar(50), required: true, index: true }
    first_name:     varchar(100)
    last_name:      varchar(100)
    created_at:     ~

  ask_interest:
    _attributes:    { phpName: Interest, idMethod: native }
    question_id:    { type: integer, foreignTable: ask_question, foreignReference: id, primaryKey: true }
    user_id:        { type: integer, foreignTable: ask_user, foreignReference: id, primaryKey: true }

  ask_relevancy:
    _attributes:    { phpName: Relevancy, idMethod: native }
    answer_id:      { type: integer, foreignTable: ask_answer, foreignReference: id, primaryKey: true }
    user_id:        { type: integer, foreignTable: ask_user, foreignReference: id, primaryKey: true }
    score:          { type: integer }
    created_at:     ~

書いているうちにうっすらどういうことか分かってきた感じがします。

MySQLとPropelの設定

InnoDBに対応するように書き換える。ついでにaskeet2というデータベースを使うように設定。

場所: askeet2/config/propel.ini

propel.database.url        = mysql://root@localhost/askeet2
propel.mysql.tableType     = InnoDB
MySQLにaskeet2というデータベースを作る。
mysqladmin5 -uroot -p create askeet2
databases.ymlを設定する。

前回はここではまったので忘れないように。
場所: askeet/config/databases.yml

all:
  propel:
    class:          sfPropelDatabase
    param:
      dsn:          mysql://root@localhost/askeet2
Propelモデルを作る
symfony propel-build-model
SQL文を作る
symfony propel-build-sql
MySQLSQL文を流す
symfony propel-insert-sql

これは便利だなーと思ったところ。

Questionアプリを作る

symfony propel-generate-crud frontend question Question

これはPropelモデルを元に勝手に作ってくれる。
できたら

symfony cc

キャッシュを削除する。

確認してみよう。


おーできてる><
何度、見てもいいですね。
ということで2日目も復習終了。