Looks nice, but can you also support the lookup over a nm-table?

So:

Users -> Users2Roles -> Roles

Users has:
user_id

Users2Roles has:
user_id
role_id

Roles has:
role_id
type


of course that is not identical to a direct lookup-table, but perhaps the
right place/module to add such a feature.



2012/10/18 Alexander Hartmaier <alexander.hartma...@t-systems.at>

>  On 2012-10-18 10:35, uro shima wrote:
>
> Dear DBIx-Class mailing list
>
> Hereby we'd like to inform you about a new package related to DBIx::Class.
>
> Its objective is to bring efficient and convenient methods for dealing
> with Lookup Tables. We call Lookup tables tables that are actually catalogs
> of terms, e.g. the table UserType with such rows: ( 1 => 'Administrator' ,
> 2 => 'User' , 3 => 'Guest' ).
>
> Let's have an example of use.
>
> package MySchema::Result::User;
> __PACKAGE__->table("user");
> __PACKAGE__->add_columns( "user_id",{}, "name", {}, "user_type_id", {} );
> __PACKAGE__->belongs_to( "UserType" => "Schema3::Result::UserType",
> {"user_type_id" => "self.user_type_id"} );
>
> # UserType Lookup table, with 2 columns (user_type_id, name) with rows: (
> 1 => 'Administrator' , 2 => 'User' , 3 => 'Guest' )
>
> # $user is a DBIx::Class::Row instance, e.g.
> $user=$schema->resultset('User')->find( name => 'Flash Gordon' )
> print $user->type; # print 'Administrator', not very impressive, could be
> written as $user->user_type()->name()
> print $user->type; # same thing, but we are sure that no database request
> is done thanks to the cache system
>
> print $user->is_type('Administrator') ? 'Ok' : 'Access Restricted';
> # equivalent (but more efficient) to
> my $type = $schema->resultset('UserType')->find( name => 'Administrator')
> or die "Bad name 'Administrator' for Lookup table UserType";
> print $user->user_type_id eq $type->id ? 'Ok' : 'Access Restricted';
>
> The features it provides are the following :
> - syntactic sugar to accessors, for example by allowing to deal with
> hard-coded value directly on the client table, e.g.
> $user->is_type('Administrator').
> - efficiency by means of a cache system for avoiding many repeated
> identical individual DBMS requests related to one entire Lookup table.
> - accessors generation automation to a whole schema.
>
> Further informations are of course available on the CPAN at the following
> URL :
> http://search.cpan.org/~rubattel/DBIx-Class-LookupColumn-0.01/lib/DBIx/Class/LookupColumn.pm
>
> Questions or comments about it are very welcome.
> Karl and Thomas
>
> Thanks for announcing this useful component to the list!
>
>
>
> *"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
> T-Systems Austria GesmbH Rennweg 97-99, 1030 Wien
> Handelsgericht Wien, FN 79340b
>
> *"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
> Notice: This e-mail contains information that is confidential and may be
> privileged.
> If you are not the intended recipient, please notify the sender and then
> delete this e-mail immediately.
>
> *"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
>
> _______________________________________________
> 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

Reply via email to