Chad wrote:> I have a Member.rb model with the following line:
>
> has_many :friends, :class_name => "Member", :finder_sql =>
"
> SELECT members.*
> FROM members, friendships
> WHERE (members.id = friendships.member_id AND friendships.friend_id >
#{self.id})
> OR (members.id = friendships.friend_id AND friendships.member_id >
#{self.id})"
>
> When calling @member.friends, the above code translates #{self.id} to
> something crazy like 53931600 instead of the @member.id which is 2.
>
> Any ideas why?
Yeah, the string is evaluated when first encountered, ie when your
Member class is loaded. At that point, I imagine self is the class,
which is why you get a weird self.id.
To prevent this use single quotes ('') around your string instead of
double quotes (").
--
Jakob Skjerning - http://mentalized.net
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---