[Dbix-class] Adding an additional custom join parameter

Hailin Hu i at h2l.name
Tue Dec 10 15:23:19 GMT 2013


Well, can you try this way?

Have join started from site_task, like this
$site_task->search(
  ...,
  join => ['site', 'task', 'issue'],
)

The relationships may be like this?
_SITE_TASK_->belongs_to('site' => 'Site');
_SITE_TASK_->belongs_to('task' => 'Task');
_SITE_TASK_->might_have('issue' => 'Issue', {'foreign.site_id' =>
'me.site_id', 'foreign.task_id' => 'me.task_id'}, {'join_type' =>
'LEFT'});

Reference:
http://search.cpan.org/~ribasushi/DBIx-Class-0.08250/lib/DBIx/Class/Relationship/Base.pm#add_relationship

I'm not sure if it works since relationship between site_task and
issue is ambiguous.
Good luck :)

On Tue, Dec 10, 2013 at 8:36 PM, Andrew Beverley <andy at andybev.com> wrote:
> On Tue, 2013-12-10 at 19:42 +0900, Hailin Hu wrote:
>> Can I ask why you need site_task table?
>> In relationship view, it is the same as issue table.
>
> That's a good question. The reason is that "issues" will often be
> generated that are not related to a "task", and likewise there will be
> "tasks" that are related to "sites" but that do not have any "issue" to
> link them (in which case the "site_task" table would be used).
>
>> It is something like that you defined one many-to-many relation (task
>> <-> site) through two bridge tables (site_task and issue).
>
> You raise a valid point though, in that this is probably a poor way to
> design such a database. Maybe I should only have one "site_task" table
> to link the "sites" and "tasks" tables, and then have appropriate fields
> within that single table to signify whether the entry is linking the 2
> tables for reason of an "issue" or a "task".
>
> http://files.andybev.com/schema.png
>
> Thanks,
>
> Andy
>
>
>
> _______________________________________________
> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk



More information about the DBIx-Class mailing list