Good evening list members,
I have the following model:
class Author < ActiveRecord::Base
has_many :authorships
has_many :books, :through => : authorships
end
Should I be able to do the following?
Author.find(:first).book_ids = [1,2,3]
Hi Christos,
What are you trying to do here? It looks to me as if you are trying to
add some books to an author... if so, how about:
a = Author.find(:first)
Book.find(1,2,3).each { |b| Authorship.create(:author=>a, :book=>b) }
or, in Rails 1.2
a = Author.find(:first)
Book.find(1,2,3).each { |b| a.books << b }
I ask, because it doesn't. The docs state that it should, but it
doesn't specialise in the case of a :through
This works fine BTW:
Author.find(:first).authorship_ids = [12,13]
Do I really need to find and add (<<) my associated join models for
books one by one?
-christos
Also, I would almost never expect to directly use foreign keys in
rails, so you should begin to wonder if you find yourself doing so...
(If I've totally missed the point here, let me know and I'll try again

Best,
-r