1

是否有可能建立某种关联:

用户型号:

has_many :goods, :through => :assignments
has_many :goods_want, :through => :assignments, :source => :good, :conditions => "assignments.type = 1"

在控制台中测试

u = User.first
u.goods_want << Good.first
u.save

正在记录:

INSERT INTO `assignments` (`good_id`, `updated_at`, `type`, `profile_id`, `created_at`) VALUES(1, '2009-03-26 09:36:11', NULL, 1, '2009-03-26 09:36:11')

那么有没有什么漂亮的方法可以使这种关联不仅从数据库中获取记录,而且可以写入数据库?

4

1 回答 1

1

你为什么不创建一个作业?

a = Assignment.new
a.type = 1
a.good = Good.first
a.user = User.first
a.save
于 2009-03-26T16:48:46.727 回答