Relationship delegated accessors using DBIC

3 messages Options
Embed this post
Permalink
Matt Whipple

Relationship delegated accessors using DBIC

Reply Threaded More More options
Print post
Permalink
Is there any built in functionality in DBIC to allow a relationship to
be defined so that the foreign fields can be accessed as though in the
present class?

I presently have part of an application that is using to tables with a
one to one relationship.  One contains user information and the other
contains the application specific data for the users (contracts).  All
of the relationships seem to be working and I can access the member
information through a, for example, $contract->member->first_name call,
but would like the higher level code to be able to treat all of the data
as simple, uniform accessors (i.e. $contract->first_name).  I'm
presently using methods for each column within the Result class but was
hoping there was an option within the relationship definition similar to
a Moose 'handles'...is there some incarnation of the proxy() method that
will do this or any other existing solution?

_______________________________________________
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@...
Peter Rabbitson-2

Re: Relationship delegated accessors using DBIC

Reply Threaded More More options
Print post
Permalink
Matt Whipple wrote:

> Is there any built in functionality in DBIC to allow a relationship to
> be defined so that the foreign fields can be accessed as though in the
> present class?
>
> I presently have part of an application that is using to tables with a
> one to one relationship.  One contains user information and the other
> contains the application specific data for the users (contracts).  All
> of the relationships seem to be working and I can access the member
> information through a, for example, $contract->member->first_name call,
> but would like the higher level code to be able to treat all of the data
> as simple, uniform accessors (i.e. $contract->first_name).  I'm
> presently using methods for each column within the Result class but was
> hoping there was an option within the relationship definition similar to
> a Moose 'handles'...is there some incarnation of the proxy() method that
> will do this or any other existing solution?
>

There is a proxy relationship attribute. More info at [1] (search for proxy)

[1] http://search.cpan.org/~ribasushi/DBIx-Class-0.08108/lib/DBIx/Class/Relationship/Base.pm#add_relationship

_______________________________________________
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@...
Matt Whipple

Re: Relationship delegated accessors using DBIC

Reply Threaded More More options
Print post
Permalink
In reply to this post by Matt Whipple
Matt Whipple wrote:

> Is there any built in functionality in DBIC to allow a relationship to
> be defined so that the foreign fields can be accessed as though in the
> present class?
>
> I presently have part of an application that is using to tables with a
> one to one relationship.  One contains user information and the other
> contains the application specific data for the users (contracts).  All
> of the relationships seem to be working and I can access the member
> information through a, for example, $contract->member->first_name
> call, but would like the higher level code to be able to treat all of
> the data as simple, uniform accessors (i.e. $contract->first_name).  
> I'm presently using methods for each column within the Result class
> but was hoping there was an option within the relationship definition
> similar to a Moose 'handles'...is there some incarnation of the
> proxy() method that will do this or any other existing solution?
Sorry...I think proxy does do what I'm looking for, I misread the docs
and sent the email as I started testing (rather than waiting to finish)

>
> _______________________________________________
> 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@...


_______________________________________________
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@...