I have two tables - Account and Enpseudo. My accounts table has an enpseudo_id. I am trying to do an inner join on Enpseudo and keep getting this error: Association named ''account'' was not found; perhaps you misspelled it? I imagine this means that I have the associations in my models sut-up wrong. In my Account model I have: belongs_to :enpseudo In my Enpseudo model I have: has_many :accounts Here is the code to my find: @accountsfrompseudo = Enpseudo.find( :all, :joins => :account, :conditions => { :accounts => { :enpseudo_id => userpseudo.enpseudo_id }}) userpseudo.enpseudo_id is a varible that I am getting from yet a third table that is just containing an enpseudo id. My question is do I have my models set-up correctly? If someone could point me to some references on rails and table set-up and associations, that would be great too. Thanks, -S -- 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-/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 -~----------~----~----~----~------~----~------~--~---
I tried enpseudo.accounts to make sure that association was working and it was. I ended up doing straight sql to get what I needed, but I thought learning how to do it the rails way would be interesting. -- 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-/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 -~----------~----~----~----~------~----~------~--~---
On Mar 13, 2009, at 12:55 PM, Shandy Nantz wrote:> I have two tables - Account and Enpseudo. My accounts table has an > enpseudo_id. I am trying to do an inner join on Enpseudo and keep > getting this error: > > Association named ''account'' was not found; perhaps you misspelled it? > > I imagine this means that I have the associations in my models sut-up > wrong. > > In my Account model I have: belongs_to :enpseudo > > In my Enpseudo model I have: has_many :accounts > > Here is the code to my find: > > @accountsfrompseudo = Enpseudo.find( :all, :joins => :account, > :conditions => { :accounts => { :enpseudo_id => > userpseudo.enpseudo_id > }}) > > userpseudo.enpseudo_id is a varible that I am getting from yet a third > table that is just containing an enpseudo id. > > My question is do I have my models set-up correctly? If someone could > point me to some references on rails and table set-up and > associations, > that would be great too. Thanks, > > -S > --You almost have it. @accountsfrompseudo = Enpseudo.find(userpseudo.enpseudo_id, :include => :accounts) Or if your "third table" (assuming Userpseudo model) class Userpseudo belongs_to :enpseudo end Then you get the same result with: @accounts_from_pseudo = userpseudo.user.accounts -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Mar 13, 4:55 pm, Shandy Nantz <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I have two tables - Account and Enpseudo. My accounts table has an > enpseudo_id. I am trying to do an inner join on Enpseudo and keep > getting this error: > > Association named ''account'' was not found; perhaps you misspelled it? > > I imagine this means that I have the associations in my models sut-up > wrong. > > In my Account model I have: belongs_to :enpseudo > > In my Enpseudo model I have: has_many :accounts > > Here is the code to my find: > > @accountsfrompseudo = Enpseudo.find( :all, :joins => :account,What you pass to :joins must exactly match the name of the association (the first argument to has_many, belongs_to etc...). So if you have has_many :accounts then you need :joins => :accounts or else you will get that error message (which is normal: you don''t have an association named account only one named accounts). 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-/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?hl=en -~----------~----~----~----~------~----~------~--~---