Ruby on Rails
Thursday, November 29, 2012
On Thu, Nov 29, 2012 at 4:29 PM, Soichi Ishida <lists@ruby-forum.com> wrote:
>https://www.google.com/search?q=rails+self+referential
Thanks. This is what I wanted.
But in my case, two model objects (in the RailsCasts, User) are equal.
So, I tried
in person.rb
has_many :give_meetinges, :class_name => "Meeting", :foreign_key =>
"give_id"
has_many :gives, :class_name => "Person", :through =>
:give_meetinges, :source => :person
has_many :take_meetinges, :class_name => "Meeting", :foreign_key =>
"take_id"
has_many :takes, :class_name => "Person", :through =>
:take_meetinges, :source => :person
I'm not sure if you need to specify the class_name for a has_many through association
in meeting.rb
belongs_to :give_person, :class_name => "Person"
belongs_to :take_person, :class_name => "Person"
this means that the foreign key is set to give_person_id and take_person_id
but in your person model, the foreign key is give_id and take_id
in the view, ('take' is person object)
<%= take.give_meetings.give_person %>
raises an error,
undefined method `give_plan' for []:ActiveRecord::Relation
Since it's 'Relation',
<%= take.give_meetings.first.give_person %>
also raises an error
undefined method `give_plan' for nil:NilClass
this is an expected error if there are no give_meetings for take. if there
is at least on give_meetings for take, this will not raise an error (assuming
that your associations and foreign keys are setup correctly)
i don't see any give_plan on your code. paste the code that stacktrace
points to the source of this error.
Can see problems in my code?
soichi
--
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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
-------------------------------------------------------------
visit my blog at http://jimlabs.heroku.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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment