5. 5
Sampleモデル
● P.200で、rails generateコマンドでモデル「Sample」を作成した。
rails generate model sample
name :string
age :integer
mail :string
tel :string
id name age mail tel create_at update_at
1 taro 10 taro@xxx 090-xxxx-xxxx 2013-9-22 ... 2013-9-22 ...
2 hanako 20 hanako@xxx 090-yyyy-yyyy 2013-9-22 ... 2013-9-22 ...
3 makopi23 3 makopi23@xxx 090-zzzz-zzzz 2013-9-22 ... 2013-9-22 ...
CREATE TABLE sample(
id SERIAL PRIMARY KEY,
name VARCHAR(255),
age INT(11),
mail VARCHAR(255),
tel VARCHAR(255),
create_at DATETIME,
update_at DATETIME);
railsコマンド SQL(MySQL)
id, create_at, update_at が自動付与される(P.225)
6. 6
Memoモデル
● P.297で、rails generateコマンドでモデル「Memo」を作成する。
rails generate model memo
sample_id :integer
title :string
comment :string
id sample_id title comment create_at update_at
1 3 third title 3番目のメモ 2013-9-22 ... 2013-9-22 ...
2 1 second title 2番目のメモ 2013-9-22 ... 2013-9-22 ...
3 2 first title 1番目のメモ 2013-9-22 ... 2013-9-22 ...
CREATE TABLE memo(
id SERIAL PRIMARY KEY,
sample_id INT(11),
title VARCHAR(255),
comment VARCHAR(255),
create_at DATETIME,
update_at DATETIME);
railsコマンド SQL(MySQL)
id, create_at, update_at が自動付与される(P.225)
関連するsampleのID番号 タイトルのテキスト 投稿するメッセージ