Kendall, thank you for your explanations, especially about migrations.
I removed my other post because i realized that in my situation the
primary key used for the association was in fact "id", so it was a bad
example.
Still, in your example, i do not understand the need for ":primary_key
=>":
Kendall Gifford wrote in post #989309:
> class User < ActiveRecord::Base
> set_table_name "tblUser"
> set_primary_key "UserID"
> has_many :comments, :primary_key => "UserID",
> :foreign_key => "PosterID"
> end
was it not working without it?
It seems redundant to write:
class Instructor < ActiveRecord::Base
set_primary_key 'person_id'
has_many :lessons, :primary_key => 'person_id'
...
end
It also does not seem to me to be strictly necessary to add to the
above:
class Lesson < ActiveRecord::Base
belongs_to :instructor, :primary_key => 'person_id'
...
end
However, i can philosophically understand the need for ":primary_key =>"
on the "belongs_to" side of association, it could serve to make this
side more independent from the "has_many" side, and avoid unexpected
behavior of Lesson if Instructor is broken ("set_primary_key
'person_id'" deleted).
It seems to me that Rails makes it possible to define and use only one
side of an association, without defining the other (otherwise the
":inverse_of =>" option probably wouldn't be useful).
I have not properly tested this situation with and without ":primary_key
=>", but so far it seems to work without, "set_primary_key 'person_id'"
seems to suffice for both sides.
So i will try to leave it like this...
P.S. the reason i am torturing Rails like that is that it also has a
convention that it should obey the human.
Seriously, i just want a nice and clear structure of my database, which
would be editable by hand (it is not going to be big), and to use Rails
just for a simple interface.
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.