[Dbix-class] Dummy DBIC columns?

Bill Moseley moseley at hank.org
Tue May 17 02:49:48 GMT 2011


I have two databases that are very similar.  For example, the "person" table
in one db has an "email" column and the other does not have that column,
otherwise the tables are the same.

My application uses the schema with the table that has the "email" column,
so there's places in the application that call $person->get_column( 'email'
), and also $person_rs->create( { name =3D> $name, email =3D> $email } );

Now, I want to use the second schema with the same application, but as
mentioned above does not have an "email" column on the person table.  it's
not important that the column does not exist.

My question is what can I do to make get_column and create (and other
methods that assume there is an "email" column) work without this column
defined in the result class.  Is there any way to have define a column that
is never used when constructing database queries?


I can create a method in the result class of the schema that doesn't have
that column:

sub email {  return 'dummy at example.com' }


And that will handle $person->email and even $person->email( $new_email ),
although I don't see that ever being used.

I'm not sure how to best override get_column(), though.  I suppose the best
approach would be to replace all the get_column() calls in the application
with actual method calls (i.e. ->email).  Or is there a way to override
get_column in this case?

What about the create() method?  Use an "around create =3D> sub {}" in the
ResultClass and strip out the "email" column?




-- =

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


More information about the DBIx-Class mailing list