I'm new to the ruby on rails and have a question about find_by_sql
method. I have two model A and B and I want to select all records from
B with the A model.
The following code: A.find_by_sql("select * from B") returns nothing.
Are there any methods to do it?
I'm new to the ruby on rails and have a question about find_by_sql
method. I have two model A and B and I want to select all records from
B with the A model.
The following code: A.find_by_sql("select * from B") returns nothing.
Foo.find_by_sql returns instances of Foo. What are you trying to do ?
I do not know is it a hack or a solution:
User.scoped :joins => "LEFT JOIN roles_users ON
roles_users.user_id=users.id WHERE role_id =
{Role.find(:first, :conditions => { :name => "admin" }, :select
=> :id).id}"
Hope it helps somebody.
With "Role.find(:first..." I have two queries, but if admin role_id
would determined in the spec it would be only one query.