Tuesday, 15 July 2014

ruby on rails - How to get fields from the child table in the result set -


I've been joined between two tables. Instruments are the original table and the status child's table. I am looking to recover only those devices which are in inst_status = 'active' child conditions table.

  i = Tools Joins (: statuses) .where ("statuses.inst_status = 'active' ')  

is a query that arises:

  SELECT" instruments ". "From" Instruments "to INNER" Conditions "go to" Conditions "" Device "_" Tools "." Id "WHERE (statuses.inst_status = 'Active')  

Which is OK He is only activating 55 devices that are active, however, how can the fields from the (child) table in the result set with the fields from the (maternal) device table be obtained?

OK, you have to use the method for this:

  Instrument.joins (: statuses) .where ("statuses.inst_status = 'active'") .select ("inst ruments. * , Position. * ")  

No comments:

Post a Comment