[Dbix-class] DynamicColumns

Karl Forner karl.forner at gmail.com
Tue Sep 18 09:29:03 GMT 2012


Hello Patrick and thanks for the answer.

There are two goals, the first is to provide dynamic virtual columns that
fool the system and seem real to it.
That goal is unfortunately useless for my intended use with
CatalystX::ExtJS::REST because I just learned it does need an actual
column, an accessor is enough.

The second goal is to deal efficiently and safely with lookup tables.
(meaning for me rather short tables containing definitions ( 1=3D>Admin,
2=3D>User, 3=3D>disabled..._)
It it is true that your suggestion works:

so that $user->type will return what I want, but...

   - it does not cache/prefetch the results, so that $other_user->type will
   trigger a DB query
   - you could I suppose add prefetching by defining a related custom
   ResultSet class, but it won't be lazy. What I want is when you do
   $user->type fior the first time, it loads the whole UserType table in ca=
ch
   - it does not help with proving methods that can use the lookup values
   safely, e.g. $user->is_permission('Administrator') will
      - check that 'Administrator' is defined in the UserType table or die
      - get the corresponding id and compare it withthe user foreign key
      - and without doing any additional query

Best,
Karl


On Tue, Sep 18, 2012 at 8:58 AM, Patrick Meidl <patrick at pantheon.at> wrote:

> On Mon, Sep 17 2012, Karl Forner <karl.forner at gmail.com> wrote:
>
> > The goal is to provide dynamic columns to dbix result objects.
> [...]
> > To be more concrete, suppose that you have User table, with a foreign
> > key user_type_id on a UserType table (a lookup table).
> > You'd like your nice extjs grid automatically filled thanks to
> > CatalystX::ExtJS::REST to display a user_type column, because the
> > "user_type_id" column is not veru useful for your customers.
> >
> > Using DBICx::DynamicColumns, you could tie the (new) method/column "typ=
e"
> > to $row->user_type()->name() for instance.
>
> isn't that exactly what you do with the 'proxy' attribute? see
>
> https://metacpan.org/module/DBIx::Class::Relationship::Base#attributes
>
> so in your User table, you would define the relationship like this:
>
> --8<-------------------------------------------------------------------
>
> __PACKAGE__->belongs_to(
>     "user_type",
>     "Your::Schema::Result::UserType",
>     { user_type_id =3D> "user_type_id" },
>     {
>         proxy =3D> {
>             type =3D> 'name',
>         },
>     },
> );
>
> --8<-------------------------------------------------------------------
>
> not sure though about your other intentions with the dynamic columns
> class.
>
>     patrick
>
> --
> Patrick Meidl ........................ patrick at pantheon.at
> Vienna, Austria ...................... http://gplus.to/pmeidl
>
>
> _______________________________________________
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20120918/47f=
6e556/attachment-0001.htm


More information about the DBIx-Class mailing list