[Dbix-class] Generating DISTINCT ON with sub query

Rippl, Steve rippls at woodlandschools.org
Wed Apr 3 16:23:12 GMT 2013


On Wed, Apr 3, 2013 at 8:55 AM, Peter Rabbitson <rabbit+dbic at rabbit.us>wrot=
e:

> On Wed, Apr 03, 2013 at 08:41:05AM -0700, Rippl, Steve wrote:
> > Have I given you enough info?
>
> I think so but I want to make sure I got it right. Tell me if the thing
> below is correct:
>
> $course_section_rs->search({}, {
> join =3D> [
>   { 'course' =3D> [     <------------------- me -> belongs_to(course)
>     { course_coursetypes  =3D> 'type' }, <-- me -> belongs_to(course) ->
> has_many(course_coursetypes) -> belongs_to(type)
>     { course_grades =3D> 'grade' }, <------- me -> belongs_to(course) ->
> has_many(course_grades) -> belongs_to(grade)
>     'course_locations',  <---------------- me ->
> has_many(course_locations)  (this one is not referenced anywhere - mistak=
e?)
>   ] },
>   { 'section' =3D> { 'section_staffs' =3D> 'staff' } } me ->
> belongs_to(section) -> has_many(section_staffs) -> belongs_to(staff)
> ]})
>
> If this is true (specifically the has_many(section_staffs) part) then thi=
s:
> > Each Section only has one teacher and belongs to one course
> can't be correct...
>
> Please clarify ;)


You are correct with the relations, logically each section should only have
one teacher but I haven't specified that and the above relations are the
ones auto-generated.  I have "CONSTRAINT section_id_staff_id PRIMARY KEY
(section_id, staff_id)" on the section_staff table when I guess just
staff_id should be the primary key?

The joins to course_coursetype and course_locations are there because in
some contexts I want to filter by location or type so my original $search
would change accordingly, but right now I'm trying to get the most general
case to work.

Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20130403/f96=
f7bc7/attachment.htm


More information about the DBIx-Class mailing list