[Dbix-class] How to use DBIx::Class on a view
Paul Makepeace
lists.rawmode.org at paulm.com
Wed Nov 16 17:53:03 CET 2005
Je 2005-11-16 16:43:09 +0000, Nigel Metheringham skribis:
> On Tue, 2005-11-15 at 20:06 +0000, Matt S Trout wrote:
> > I reckon your primary key is (date,bs_group,feature).
>
> That seems right...
>
> However that gives me another issue. bs_group and feature are keys into
> other tables, so I wanted to make them has_one relationships, which gave
> me a class content like this.... (slightly shortened):-
> __PACKAGE__->table('group_date_feature_map');
> __PACKAGE__->add_columns(qw/date bs_group feature count/);
> __PACKAGE__->set_primary_key(qw/date bs_group feature/);
>
> # set up the relationships
> __PACKAGE__->belong_to(bs_group => 'App::M::Database::BsGroup');
> __PACKAGE__->belong_to(feature => 'App::M::Database::Feature');
>
>
> Now when I try and retrieve some data from this table I get:-
> Can't find unless primary columns are defined
> at /usr/local/share/perl/5.8.7/DBIx/Class/Relationship/Base.pm
> line 260
(Have you defined PKs for ::BsGroup and ::Feature?)
> [Also, trivial mini-question. Whats the DBIC equivalent to the CDBI
> retrieve_all ?]
Class->search;
I've added some docs on this in the repository but it's not released yet.
=item search
my @obj = $class->search({ foo => 3 }); # "... WHERE foo = 3"
my $cursor = $class->search({ foo => 3 });
To retrieve all rows, simply call C<search()> with no condition
parameter,
my @all = $class->search(); # equivalent to search({})
If you need to pass in additional attributes (see
L<DBIx::Class::ResultSet/Attributes> for details) an empty hash indicates
no condition,
my @all = $class->search({}, { cols => [qw/foo bar/] }); # "SELECT foo, bar FROM $class_table"
=cut
HTH,
Paul
--
Paul Makepeace .............................. http://paulm.com/inchoate/
"What is that sound of scratching in my freezer? To snuggle with a
fish."
-- http://paulm.com/toys/surrealism/
More information about the Dbix-class
mailing list