[Dbix-class] DynamicColumns

Karl Forner karl.forner at gmail.com
Tue Sep 18 09:30:19 GMT 2012


On Tue, Sep 18, 2012 at 11:13 AM, Ian Docherty
<dbix-class at iandocherty.com>wrote:

> Karl.
>
> On 17 September 2012 22:20, Karl Forner <karl.forner at gmail.com> wrote:
> > Hello dear DBICx users,
> >
> > I am currently working on a project, and I suddenly realized that I
> should
> > have asked for your wise suggestions before
> > jumping into that maybe useless project.
> >
> > The goal is to provide dynamic columns to dbix result objects. I was
> > inspired by the DBICx::VirtualColumns package, but I do not store any
> value
> > into the row object, just override methods that use user supplied
> callbacks
> > to get the value.
> >
> > The overall intended usage is to provide some "view" columns that can be
> > transparently used as is they were actual columns, for instance by
> > CatalystX::ExtJS::REST
> > to provide a table view of the tables that incorporate the new columns.
> >
> > To be more concrete, suppose that you have User table, with a foreign k=
ey
> > 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.
>
> I did something very similar, but did not think that it warranted a
> module to do it.
>
> In my case, all I did was to add a method to the DB/Result/User.pm module
>
> sub user_type {
>     my ($self) =3D @_;
>     return $self->user_type->name;
> }
>
> I don't think it comes much simpler than that, although for efficiency
> you may want to also do a prefetch on the user_type table.
>


Hello Ian,

Thanks for replying, see my answer to the previous post.

Best,
Karl



>
> >
> > Using DBICx::DynamicColumns, you could tie the (new) method/column
> "type" to
> > $row->user_type()->name() for instance.
> >
> > Another intended use is to provide accessors for another project that
> will
> > provide some optimized cache and useful accessors/checks for this kind =
of
> > Lookup tables.
> >
> > I currently have a prototype that only works for one table, and that is
> very
> > hackish because I sometimes have to hide the dynamic columns, and so wr=
ap
> > the methods that should not see those dynamic columns.
> >
> > What do you think ??
> > Is-it a valid approach ?
> >
> > Thanks.
> > _______________________________________________
> > 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
>
> _______________________________________________
> 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/0bc=
7dab7/attachment.htm


More information about the DBIx-Class mailing list