Skip to content

Instantly share code, notes, and snippets.

@brandon-beacher
Created August 28, 2012 01:30
Show Gist options
  • Save brandon-beacher/3494105 to your computer and use it in GitHub Desktop.
Save brandon-beacher/3494105 to your computer and use it in GitHub Desktop.
# this is a bit of a hack to make a join on two keys:
# classroom_id and student_id
# we pretend classroom_id is the primary key
# then we add a condition for student_id
# the result is an association joined on two keys
has_many :enrollments,
foreign_key: :classroom_id,
primary_key: :classroom_id,
conditions: Proc.new { { enrollments: { student_id: student_id } } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment