Christopher H. Laco wrote:
>Steven Mackenzie wrote:
>
>
>>Why is there no accessor in the schema class for each table? Wouldn't it
>>be obvious to type
>> $schema->MyTableClass->search( .. )
>>
>>Not quite as brief as the CDBI style, but resultset('') starts to hurt
>>my fingers (especially the punctuation parts of it ...)
>>
>>Steven
>>
>>
>
>Don't always assume that table eq 'tableclass', or even schema class.
>The three need not be related by name in any way.
>
> package My::Schema::Foo;
> __PACKAGE__->table('stuff');
> __PACKAGE__->source_name('MyBar');
>
> $schema->resultset('MyBar')->search;
>
>
> package My::Schema::Foo2;
> __PACKAGE__->table('stuff');
> __PACKAGE__->add_column('evenmore');
> __PACKAGE__->source_name('MyBest');
>
> $schema->resultset('MyBest')->search;
>
>
>You can use two resultsource classes against the same table(), kind of
>like inherited tables.
>
>
>
Aha, I see. In the example above, the base table in the DB has a full
set of columns, and My::Schema::Foo presents one subset of them, and
My::SchemaFoo2 exposes another set of them? It's possible that my head
wouldn't be able to navigate three layers of indirection (source
name->package name->table name), but nothing forces me to write code
that uses it, so that's OK :-)
In the example above, if the same row from the base class is
instantiated as a Foo and a Foo2, are the column values synchronised? If
not, then it's more correct to stick to a single class per table surely?
In my quest to avoid typing resultset(''), is there a reason why I can't
have source_name create accessors in the $shema object, eg,
$schema->MyBest->search;
_______________________________________________
List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
Wiki: http://dbix-class.shadowcatsystems.co.uk/
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
Searchable Archive: http://www.mail-archive.com/[email protected]/