[Dbix-class] Thoughts about "complex" searches.
Jesper Krogh
jesper at krogh.cc
Tue Dec 6 09:58:27 CET 2005
I discussed this on IRC the other day and the initial response was to create
a view in the database for the purpose. View's are just evil since they
usually dont allow updating the table in the proper way.
So. The problem is:
Given the artist that has many traces.
Artists: (aid, name,birth, etc, etc)
Tracks: (tid,aid,name,recorded, etc. etc.)
I'd like to search for the "joined set". Give me the tracks that
has been recorded by artists born before a given date.
This is easily composed in SQL by :
select tid from artists,tracks where artist.aid = tracks.aid and
artists.birth < $date;
And should return (in DBIx::Class terms) an iterator on tracks, which
by the nature of the ORM gives easy access to the artist.
There is a quite common subset of table-joins that seems fit well
in the concept of the ORM. Allthough more "complex" things af "left outer
joins" and stuff like that are harder to fit in.
A suggestion would be to implement a $table->search_joined() that
can just join the tables on the keys and put a SQL::Abstract-where clause
on that query.
Have I missed something obvious? Does people really prefer to solve this
usecase using a view?
Jesper
--
Jesper Krogh
More information about the Dbix-class
mailing list