如何:
先让模型的事实是一个苦差事可以关联到很多孩子
Kid:
has_many :kid_chore
has_many :chores, :through=>:kid_chore
KidChore:
belongs_to :kid
belongs_to :chore
Chore:
has_many :kid_chore
has_many :kid, :through=>:kid_chore
,如果你愿意的话,可以使用电子钱包的KidChore表的名称。
其次每个家务已完成或没有完成
class Chore < ActiveRecord::Migration
def self.up
create_table :chore do |t|
t.string :name
t.date :start_date
t.date :end_date
t.string :status # done or not done
#...all the field that you like
t.timestamps
end
end
高清self.down drop_table:苦差事 结束 结束
现在,你想现在多少琐事每个孩子做了
的
class KidChore < ActiveRecord::Migration
def self.up
create_table :kid_chore do |t|
t.integer :kid_id
t.integer :chore_id
t.integer :percentage_done # done or not done
#...all the field that you like
t.timestamps
end
end
def self.down
drop_table :kid_chore
end
end
希望得到这个帮助。
真的很有帮助...非常感谢。 – chris 2011-04-27 02:45:56