Wednesday, March 20, 2013

[Rails] using multiple joins in queries

I have this query:

Report.
joins(:alerts).
joins(:alert_code).
where(:unit_id => unit_id).
where{time < my{self.time}}.
where("alert_codes.name LIKE ?", "%Inside virtual
fence%").
order("reports.time DESC").first

Basically, it breaks:

ActiveRecord::ConfigurationError (Association named 'alert_code' was
not found; perhaps you misspelled it?):


My associations look like this:

report has_many alerts
alert belongs_to :alert_code, :foreign_key => :code

I am trying to get the first report whose alerts belongs to alert_code
whose name is "inside virtual fence". So there are 3 associations
here. Trying to establish the connection.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate