Skip to content

Instantly share code, notes, and snippets.

@errakeshpd
Last active August 29, 2015 14:11
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 errakeshpd/5f2c7e247cd3a1370543 to your computer and use it in GitHub Desktop.
Save errakeshpd/5f2c7e247cd3a1370543 to your computer and use it in GitHub Desktop.
how to write this in rails ORM method ?
SELECT et.id
FROM examtypes et
LEFT JOIN categoryexams ce ON et.id = ce.examtype_id
LEFT JOIN categoryexamusers ceu ON ce.id = ceu.categoryexam_id
LEFT JOIN categoryusers cu ON cu.id = ceu.categoryuser_id
LEFT JOIN users u ON u.id = cu.user_id
WHERE u.id =71
@errakeshpd
Copy link
Author

examtype
has_many :categoryexams

exam
has_many :categoryexam, :dependent => :destroy

category_exam_user
belongs_to :categoryexam
belongs_to :categoryuser

category_exam
belongs_to :exam
belongs_to :examtype
has_many :categoryexamuser
has_many :categoryusers, :through => :categoryexamuser

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment