# Need help with (simple?) find statement

**URL:** <https://www.ruby-forum.com/t/need-help-with-simple-find-statement/114956>\
**Category:** Rails\
**Created:** [September 19, 2007, 8:31am UTC](https://www.ruby-forum.com/t/need-help-with-simple-find-statement/114956 "2007-09-19T08:31:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vince](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b5e925/32.png) [@vince](https://www.ruby-forum.com/u/vince)\
**Post date:** [September 19, 2007, 8:31am UTC](https://www.ruby-forum.com/t/need-help-with-simple-find-statement/114956/1 "2007-09-19T08:31:44Z")

</div>

I have a basic enrollment system where a user can enroll in a course  
either as a student or instructor.

users(login)  
enrollments(user\_id, course\_id, type\_user\_id)  
courses(title)  
type\_users(title) where title is ‘instructor’ or ‘student’

I need to list all the courses for which a user is the instructor so I  
wrote this

user.courses.find(:all, :include =\> {:enrollments =\> :type\_user},  
:conditions =\> “type\_users.title =  
‘instructor’”)

What this is returning, however, is all the courses the user is  
enrolled in that has an instructor. Thanks for any help!

---

<div class="post-metadata">

**Author:** ![vince](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b5e925/32.png) [@vince](https://www.ruby-forum.com/u/vince)\
**Post date:** [September 19, 2007, 10:02am UTC](https://www.ruby-forum.com/t/need-help-with-simple-find-statement/114956/2 "2007-09-19T10:02:04Z")

</div>

vince wrote:

> user.courses.find(:all, :include =\> {:enrollments =\> :type\_user},  
> :conditions =\> “type\_users.title =  
> ‘instructor’”)
> 
> What this is returning, however, is all the courses the user is  
> enrolled in that has an instructor. Thanks for any help!

What does your SELECT statement look like?

–  
Michael W.
