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

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


On Wed, 2005-11-16 at 17:18 +0000, Matt S Trout wrote:
> On Wed, Nov 16, 2005 at 04:43:09PM +0000, Nigel Metheringham wrote:
> > 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');

Ugh - typo in previous 2 lines (belong_to should be belongs_to).

> I'm not sure you're using find how you think you are. Try
> 
> $class->find($date, $bs_g, $feature);

I'm not trying to get a particular row from this table - so I'm neither
explicitly, nor as far as I can see/expect implicitly calling find on
this class.

What I'm trying to do is get it so 
	my($record) = App::M::Database::GroupDateFeatureMap->search;
	$record->feature
gives me a App::M::Database::Feature record corresponding to the PK id
in the group_date_feature_map.feature SQL row.

instead the belongs_to relation appears to be doing something unexpected
(to me) related to the PK of this table.

I'll try and build a smaller (BeerDB?) example that shows this - could
be useful anyhow for testing out my understanding and adding some stuff
to the wiki :-)


> $class->find({ date => $date, bs_group => $bs_g, feature => $feature });
> 
> Find is designed to retrieve a single record by PK - if you just want to get
> back a set of results matching a given condition, use ->search

I can get the fields I want of this view returned OK - its the related
table rows that are giving me grief...

	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