Let me explain I have these models class User < AR::Base has_many :contact end class Contact < AR::Base belongs_to :user belongs_to :user_contact_id, :class_name => "User", :foreign_key => "user_contact_id" # I have field called :user_contact_id who is the another user record of the user table. def self.is_contact?(user_contact_id) # CHECK IF THE USER ALREADY HAVE A CONTACT WITH THE USER_CONTACT_ID # end end I''ve an instantiated User class, @user, and want to do the following @user.contacts.is_contact?(user_contact_id) # This works like a charm. My question is, how can i access the @user caller object from the self.is_contact? method in Contact Class? Is this possible? Thanks. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> @user.contacts.is_contact?(user_contact_id) # This works like a charmIt does? What''s the content of the "is_contract?" function? It might be easier to help if you tell us what you''re trying to achieve. What are you going to do once you know if the user have / doesn''t have a contract with that user_contract_id? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Feb 5, 3:22 pm, "Augusto Ruibal (Shinta)" <augusto.rui...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: e an instantiated User class, @user, and want to do the following> > @user.contacts.is_contact?(user_contact_id) # This works like a charm. > > My question is, how can i access the @user caller object from the > self.is_contact? method in Contact Class? Is this possible? >you can''t. What do you need it for ? - any find you do on Contacts from inside is_contact? will be magically scoped to @user''s contacts anyway. Fred -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Feb 5, 10:22 am, "Augusto Ruibal (Shinta)" <augusto.rui...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Let me explain > > I have these models > > class User < AR::Base > has_many :contact > end > > class Contact < AR::Base > belongs_to :user > belongs_to :user_contact_id, :class_name => "User", :foreign_key => > "user_contact_id" # I have field called :user_contact_id who is the > another user record of the user table. > > def self.is_contact?(user_contact_id) > # CHECK IF THE USER ALREADY HAVE A CONTACT WITH THE USER_CONTACT_ID > # > end > end > > I''ve an instantiated User class, @user, and want to do the following > > @user.contacts.is_contact?(user_contact_id) # This works like a charm. >A plain :through could do what you''re looking for: class Contact < AR::Base belongs_to :user belongs_to :user_contact, :class_name => "User" end class User < AR::Base has_many :contacts has_many :user_contacts, :through => :contacts end (you may need a :source and/or :class_name on :user_contacts, try it and see) Then you can do: @user.user_contacts.include?(some_other_user) --Matt Jones -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.