Having a brain fart on on this one, maybe someone can set me straight i have a model that can be requested by and assigned to a user so i have an ''assigned_to_id'' column and a ''requested_by_id'' column. Now originally i had setup the models as: class Thing < ActiveRecord::Base belongs_to :requester, :class_name => "User", :foreign_key => "requested_by_id" belongs_to :assignee, :class_name => "User", :foreign_key => "assigned_to_id" ... end class User < ActiveRecord::Base has_many :requested_things, :class_name => "Thing", :foreign_key => "requested_by_id" has_many :assigned_things, :class_name => "Thing", :foreign_key => "assigned_to_id" end class User < ActiveRecord::Base has_many :things do def requested find(:all, :conditions => ''requested_by_id = #{id}'' end def assigned find:all, :conditions => ''assigned_to_id = #{id}'' end end but attempting to do @user.things.requested results in: SELECT * FROM things WHERE (things.user_id = 1 AND (assigned_to_id = #{id})) where i want SELECT * FROM pick_requests WHERE (things.assigned_to_id = 1) so is there a way to do what i am trying to do or should i just stick with the first attempt? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hello Chris,> Having a brain fart on on this one, maybe someone can set me > straight > > i have a model that can be requested by and assigned to a > user so i have an 'assigned_to_id' column and a 'requested_by_id' > column. Now originally i had setup the models as:[...]> class User < ActiveRecord::Base > has_many :things do > def requested > find(:all, :conditions => 'requested_by_id = #{id}'There's a missing parenthesis. Paste error, I'm guessing.> end > def assigned > find:all, :conditions => 'assigned_to_id = #{id}' > end > end > > but attempting to do > > @user.things.requested results in: > > SELECT * FROM things WHERE (things.user_id = 1 AND (assigned_to_id = #{id}))Are you sure ? Doesn't it generate : SELECT * FROM things WHERE (things.user_id = 1 AND (requested_by_id = #{id}))> where i want > > SELECT * FROM pick_requests WHERE (things.assigned_to_id = 1)Are sure this SQL statement is correct ?> so is there a way to do what i am trying to do or should i just stick > with the first attempt?It's not clear to me what you attempt to do, what is pick_requests ? where does it come from ? -- Jean-François. -- À la renverse. --~--~---------~--~----~------------~-------~--~----~ 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 this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
good catches on the typos. i was trying to be a bit abstract and missed a couple of things On 10/26/06, Jean-François <jf.web3-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello Chris, > > > Having a brain fart on on this one, maybe someone can set me > > straight > > > > i have a model that can be requested by and assigned to a > > user so i have an ''assigned_to_id'' column and a ''requested_by_id'' > > column. Now originally i had setup the models as: > [...] > > class User < ActiveRecord::Base > > has_many :things do > > def requested > > find(:all, :conditions => ''requested_by_id = #{id}'' > > There''s a missing parenthesis. Paste error, I''m guessing.yes, bad paste.> > > end > > def assigned > > find:all, :conditions => ''assigned_to_id = #{id}'' > > end > > end > > > > but attempting to do > > > > @user.things.requested results in: > > > > SELECT * FROM things WHERE (things.user_id = 1 AND (assigned_to_id = #{id})) > > Are you sure ? > Doesn''t it generate : > > SELECT * FROM things WHERE (things.user_id = 1 AND (requested_by_id = #{id})) >another bad paste, you are correct.> > where i want > > > > SELECT * FROM pick_requests WHERE (things.assigned_to_id = 1) > > Are sure this SQL statement is correct ? >another bad paste, should be SELECT * FROM things WHERE (things.assigned_to_id = 1)> > so is there a way to do what i am trying to do or should i just stick > > with the first attempt? > > It''s not clear to me what you attempt to do, what is pick_requests ? > where does it come from ? > > -- Jean-François. > > -- > À la renverse. > > > >--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---