ActiveRecord query with conditionals on nested associations?

Try this: p = Person. Includes(:roles => :application). Where(:loginid => 'their_loginid', :role_id => Application.

Find_by_api_key('api_key'). Role_ids).

Though it seems unnecessary, what I want to do is something like: Person. Joins(:roles => :application). Where(:loginid => 'cthielen', :roles => {:application => {:id => 1}} which doesn't work.(I'm going to query for a non-id element, api_key, part of application, which is why I need that extra bit of nesting.) – Chris Aug 11 at 19:33 1 Thanks for the help.

I did get it working via: Person. Joins(:roles => :application). Where(:loginid => 'their_loginid', :roles => {:applications => {:api_key => 'the_api_key'}}) – Chris Aug 11 at 19:37 Oops, not quite there yet.

I did get it working via: Person. Joins(:roles => :application). Where(:loginid => 'their_loginid', :roles => {:applications => {:api_key => 'the_api_key'}}) but for some reason that does not actually return the roles associated with that application.

E.g. P = Person. Find_by_loginid("their_id") will return a valid p.

Roles but the query above gives me an error on p.roles. How do I include the roles associated with that application_id? – Chris Aug 11 at 19:43 Still not working with the change to includes(), the query doesn't error out but p.

Roles (p = Person...) still does not exist: p = Person. Includes(:roles => :application). Where(:loginid => 'their_loginid', :roles => {:applications => {:api_key => 'the_api_key'}}).

To_sql => "SELECT \"people\". * FROM \"people\" WHERE \"people\". \"loginid\" = 'their_loginid' AND \"applications\".

\"api_key\" = 'the_api_key'" – Chris Aug 11 at 19:49.

I'd like to query all the roles a person has for a given application. Which works, but it's querying based on Person.roles. Application_id; instead, I'd like to query based on Person.roles.application.

Api_key (another property of an application). Leading me to think my usage of ActiveRecord isn't joining the tables together correctly.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions