[Dbix-class] join to tables has two "identical" columns

David Ihnen davidihnen at gmail.com
Fri Mar 19 01:51:37 GMT 2010


Set up two different relationships, one describing the relationship to each
column specifically, with a join type option of outer.

Query a joining across both relationships and constrain by table2left.left
is not null or table2right.right is not null

Make sense?

David

On Thu, Mar 18, 2010 at 11:40 AM, nhyda <nhydanhyda at gmail.com> wrote:

> I am trying to use DBIx::Class in Catalyst
> Here is my problem.
> I have two tables as shown below
> Table 1             Table 2
> id  name      id  left right
> 1   A            1    A   B
> 2   B            2    B   C
> 3   C            3    C   D
> 4   D            4    A    E
> 5   E            5    B    E
>
> I want to list who is B's neighbor.
> result expected
> 1 A
> 2 C
> 3 E
>
> I have two has_many relationship defined in Table 1
> __package__->has_many ("at_left","DB::Table2",{left=3D
> >"name"})
> __package__->has_many ("at_right","DB::Table2",{right=3D>"name"})
> and corresponding belongs_to in Table 2
>
> I want to do something like
> select name from table 1 as t1
> join table 2 as t2 on t1.name =3D t2.left or t1.name =3D t2.right
>
> How do I put it into model(DB::Table1) ->search ?
>
> any help or idea is appreciated
>
> _______________________________________________
> 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
>



-- =

"If only I could get rid of hunger by rubbing my belly" - Diogenes
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20100318/8f7=
39aea/attachment.htm


More information about the DBIx-Class mailing list