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
[email protected]
--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---