[Dbix-class] Can add_column be called on a Row?
Bill Moseley
moseley at hank.org
Sat Oct 4 20:56:24 GMT 2014
On Sat, Oct 4, 2014 at 12:04 PM, Peter Rabbitson <rabbit+dbic at rabbit.us>
wrote:
>
>> The problem in its core (and this has always been the case) is that:
> My::App::Schema::Result::Foo->result_source_instance
> !=
> My::App::Schema->source('Foo')
> !=
> $my_app_schema_instance->source('Foo')
>
> The change in 4006691d207 makes things consistently work on the "current
> instance level", whereas before it was not entirely clear where the
> ResultSourceProxy call will actually land.
>
> Does this answer your question? Is there something I missed when
> implementing this part?
That answers my question -- I don't think it makes sense to call add_column
on a row object, which is what our code was doing. I don't know why they
(meaning our developer) used this approach instead of just adding
additional attribute's the the result class -- or perhaps creating a
subclass with the extra attributes.
Is that the suggested approach now? If you have a result class for, say,
"Employee" and you wanted to add meta data (meaning associated attributes
that are not stored in the database) for only a subset of Employees that
are "retired" is this still the way to go?
That is something like:
package Employee;
use base 'DBIx::Class::Core';
__PACKAGE__->table( 'employee' );
__PACKAGE__add_columns( ... );
...
1;
package RetiredEmployee;
use Moose;
extends 'Employee';
__PACKAGE__->table( 'employee' );
__PACKAGE__->source_name( 'RetiredEmployee' );
has current_age => ( ... ); # for lack of a better example.
1;
--
Bill Moseley
moseley at hank.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20141004/ad69a72d/attachment.htm>
More information about the DBIx-Class
mailing list