#rubyonrails - Sat 31 Mar 2007 between 06:22 and 06:28

NY Lost Funds



Palishclassroom has many sections
ReinHPalish: no you don't
Palishsection has many users
input: user_id and classroom_id
ReinHok, and you want to find out if a user is in a classroom?
Palishoutput: true if student_entry exists such that Section.find(section_id).classroom_id = existing_classroom_id
where section_id came from StudentEntries
ReinHPalish: ok, and you want to find out if a user is in a classroom?
Ashimsokay Palish, basically think of it this way, the subquery (the thing inside the brackets) will return a table... make sure its one col wide. then you can use the in thing
Palishyes
ahh
ReinHPalish: ok, so you have @classroom and @student
Palishuser, but sure.
ReinHand you want to find out if that @student is in that @classroom (through its sections)
Palishyes
@classroom.sections[whatever][0] == user? maybe
what I meant by that was, it COULD be true
ReinHone sec
AshimsBigFisch! they're ignoring me! you win!
ReinHwhat are the associations between sectino and classroom and section and student?
PalishAshims: Okay so the problem with that is that I need the section_id which came from teh student entry
ReinH*section
Palish: don't listen to the drunk man... try to do this the rails way first
section has_many students belongs_to classroom?
Classroom has_many :students, :through => 'sections'
@classroom.students.include? @student
Done.
PalishAshims: So let's say I have a section, which refers to classroom_id 'awesome'. The section's id is '5'. So now we have a student_entries entry which says { some_user_id, '5' }. So somehow in that IN, I need to get the '5'
ReinH: interesting..
what's include do?
Ashimskk Palish... 1 sec... reading
PalishClassroom doesn't have 'students'
ReinHas long as you do classroom has_many :sections, :include => 'students'
Palishclassroom has sections.
ReinHPalish: yes, thus the :through
PalishI don't understand what that :include part does
ReinHsigh
BigFischit is a join table
ReinH:include does an OUTER JOIN to pull the section's students with the section
which may not be what you want to do all the time

Page: 2 9 16 23 30 37 44 51 58 65 72 79 

IrcArchive

NY Lost Funds