views:

24

answers:

1

Hello, in my users model, I have the following:

@users = find(:all, :joins => :instance, :conditions => ['fname LIKE ? or lname LIKE ?', "%#{search}%", "%#{search}%"])

The issue here is that @users only returns data from the user's table, and not the joined instance table. I confirmed this with the SQL query in the logs.

SELECT "users".* FROM "users" INNER JOIN "instances" ON "instances"."id" = "users"."instance_id" WHERE (fname LIKE '%%' or lname LIKE '%%')

How can I make rails SELECT users.* and instance.name ?

Thanks

+1  A: 

can you use the :select option and specify "users.*, instance.name"?

Beerlington
Thanks, but that seems like such a hack... Is it? Why would you join tables and not include the results of the other table? trying to understand what Rails is doing and why?
AnApprentice
I'd consider it a hack. Normally when you do a query in rails, you are only getting the results of the model you are querying, in your case User. How are you planning on using the instance name? The standard way would be to get it with user.instance.name instead, and not including it in your select.
Beerlington