[Dbix-class] Dummy DBIC columns?

Bill Moseley moseley at hank.org
Wed May 18 17:01:48 GMT 2011


On Wed, May 18, 2011 at 2:11 AM, Alexander Hartmaier <
alexander.hartmaier at t-systems.at> wrote:

>  Why not create another result class for the different table?
> The overlapping methods can be put in a base class or a role used by both.
>

That's exactly what I'm doing.  I've got two schemas and associated Result
and ResultSet classes that use Roles to bring in common functionality.

The problem is this:

my %new_user =3D (  first =3D> 'jane', last =3D> 'Doe', email =3D> '
jane_doe at example.com' );

my $schema =3D $user_other_schema ? $alt_schema : $original_schema;

my $user =3D $schema->resultset( 'User' )->create( \%new_user );


Now, if $alt_schema's User class doesn't define an "email", because the
underling table doesn't have that column, then things blow up.

So, I'm wondering how to have a "virtual" email column in that class -- or
some way to make DBIC happy that "email" is not a defined column.  Or
perhaps override create (or lower-level insert or update) and remove that
column from the passed in data.

What would be better is to have a layer between the app and the DBIC schema
(i.e. $model->create_user( \%new_user ) ) where I could handle this easier,
but this is an existing app and the app currently uses DBIC pretty
extensively and assumes it has a $schema object to work with.

Handling $user->email is easy, because I can just add that method.  I
suppose I can override $user->get_column( 'email' ) to filter those out.


-- =

Bill Moseley
moseley at hank.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20110518/1a5=
c26f7/attachment.htm


More information about the DBIx-Class mailing list