[Dbix-class] RFC - has_subset

Daniel Ruoso daniel at ruoso.com
Mon Mar 31 12:45:04 BST 2008


Hi,

I'm working on an application that have the following classes:

  TaskType --- has_many ---> TaskTypeFile

but, that can actually be seen as two relationship types:

          ____ has_many { type => input } __
         /                                  \
  TaskType                            TaskTypeFile
         \____ has_many { type => output }__/

Or, this could be seen as:

                                TaskTypeFile
                               /\          /\
                                |          |
                               is          is
                                |          |
                           InputFile     OutputFile
           _______ has_many__/            |
          /                               |
  TaskType --------------- has_many ------/

But one could see InputFile and OutputFile simply as a subset of
TaskTypeFile, and once this is done, we can keep the simplicity of
the first diagram, and filter on the TaskTypeFile as needed, which also
enables the input/output view independent on the TaskType relationship.

So, instead of doing

$tasktypers->input_files
$tasktypers->output_files

I could do

$tasktypers->files->input
$tasktypers->files->output

The major difference in that is that I can do 

my $rs = TaskType->find($id, { prefetch => 'files' });
while ($rs->files->input) {...}
while ($rs->files->output) {...}

With a single query, as the input/output resultset would simply
implement a filter on the previous resultset, while

TaskTypeFile->input->search({ name => 'foo.txt' });

would still be possible.

So, the proposed interface is:

__PACKAGE__->load_components( ... Subset ... );
...
__PACKAGE__->has_subset('input', { type => 'input' });
__PACKAGE__->has_subset('output', { type => 'output' });

It would add that as a part of the where clause when no cache is
present, and grep on the cache when already prefetched...

I still didn't go through the coding, so, this is the time for any
comments or tomatoes...

daniel




More information about the DBIx-Class mailing list