[Dbix-class] Confused by search_related

Paul Makepeace paulm at paulm.com
Sat Oct 6 15:00:32 GMT 2007


In the docs http://search.cpan.org/~ash/DBIx-Class-0.08007/lib/DBIx/Class/Relationship.pm
there's an example of search_related doing a "select *" which I think
is misleading as it's actually only selecting from the related
resultset not the base(?) resultset, at least in my experiments.

I have SavedView with,

__PACKAGE__->belongs_to('web_chart_spec' =>
'IDL::Schema::WebChartSpec' => 'web_chart_spec_uid');

My controller does,

  my @saved_views :Stashed =
$c->model('DBIC_Readonly')->resultset('SavedView')->search_related(
		'web_chart_spec' => {service_profile_uid => $chart->{service_profile_uid}});

I get results but nothing from SavedView, just WebChartSpec! Debugging
the SQL reveals it's only selecting on web_chart_spec.*. I dunno, if I
called "resultset('SavedView')" I'm expecting stuff with SavedView in
it.

How can I achieve what I'm intending here? In essence,

select sv.* from saved_view sv
join web_chart_spec ws on ws.uid = sv.web_chart_spec_uid
where ws.service_profile_uid = ?;

  my @saved_views :Stashed =
$c->model('DBIC_Readonly')->resultset('SavedView')->search(
		{'web_chart_spec.service_profile_uid' => $chart->{service_profile_uid}},
		{join => ['web_chart_spec']});

Works but maybe there's a nicer way.

P



More information about the DBIx-Class mailing list