views:

121

answers:

1

Is it possible to make some kinda this association:

User model:

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

Testing in console

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

This is being logged:

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')

So is there any beautiful way to make this association work not only to get records from database, but to write into database?

A: 

Why don't you create an Assignment?

a = Assignment.new
a.type = 1
a.good = Good.first
a.user = User.first
a.save
Can Berk Güder