[Dbix-class] How to use DBIx::Class on a view

Nigel Metheringham nigel.metheringham at dev.intechnology.co.uk
Wed Nov 16 18:12:51 CET 2005


On Wed, 2005-11-16 at 16:53 +0000, Paul Makepeace wrote:
> Je 2005-11-16 16:43:09 +0000, Nigel Metheringham skribis:
> > 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
(I meant belongs_to relationships - previous CDBI experience made me try
to use has_a/has_one instead)
> > 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?)

Yes - and to test it I just recoded my test script to do:-
        my $set = App::M::Db::GroupDateFeatureMap->search;
        
        while (my $rec = $set->next) {
            my $frec = App::M::Db::Feature->find($rec->feature);
            my $grec = App::M::Db::BsGroup->find($rec->bs_group);
        ...

(having commented the belongs_to lines in the module def)

so the moral equivalent of what I would expect the ORB to be doing, and
that works fine.

> > [Also, trivial mini-question.  Whats the DBIC equivalent to the CDBI
> > retrieve_all ?]
> 
>   Class->search;

Damn - I thought I had tried that and had it throw an error
(specifically it generated a piece of SQL with an empty WHERE clause),
but now I try it again and it works fine.

Thanks
	Nigel.
-- 
[ Nigel Metheringham           Nigel.Metheringham at InTechnology.co.uk ]
[ - Comments in this message are my own and not ITO opinion/policy - ]





More information about the Dbix-class mailing list