Skip to content

Instantly share code, notes, and snippets.

@arnab
Created November 2, 2009 04:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arnab/223925 to your computer and use it in GitHub Desktop.
Save arnab/223925 to your computer and use it in GitHub Desktop.
If you want to load data from 2 tables (with a belongs_to/has_many relation)
metrics_with_inputs = Revision.find(
:all,
:conditions => { :id => self.revisions.map { |r| r.id } },
:select => 'revisions.metric, revisions.snap_date, revisions.updated_at,
inputs.author, inputs.as_of_date, inputs.units',
:joins => 'join inputs on inputs.revision_id = revisions.id',
:order => 'revisions.metric, revisions.snap_date, revisions.updated_at'
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment