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=>Admin, 2=>User, 3=>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 cach - 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 <patr...@pantheon.at> wrote: > On Mon, Sep 17 2012, Karl Forner <karl.for...@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 "type" > > 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 => "user_type_id" }, > { > proxy => { > type => 'name', > }, > }, > ); > > --8<------------------------------------------------------------------- > > not sure though about your other intentions with the dynamic columns > class. > > patrick > > -- > Patrick Meidl ........................ patr...@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 >
_______________________________________________ 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