[Dbix-class] has_many but no left join?!
Stephen Shorrock
stephen.shorrock at gmail.com
Tue Jun 18 18:06:30 GMT 2013
Hi,
I was wondering if anyone could offer some insight into a problem I'm
finding. I wish to create a relationship using a left join by this doesn't
appear to be happening when I trace the SQL. My only thought is that it is
something to do with using a 'table' without a primary key or whose
underlying database object is actually not a table but a view?
The example class / relationship below doe snot produce a left join, but
would have thought it aught to:
Package MyApp::Schema::Result::IndexStatus;
__PACKAGE__-table("index_statuses");
__PACKAGE__->add_columns( "myindex",
{ data_type =3D> "bigint", is_nullable =3D> 0 },
"myoldindex",
{ data_type =3D> "bigint", is_nullable =3D> 0 },
"mystatus",
{ data_type =3D> "varchar", default_value =3D> "", is_nullable =3D> 0, si=
ze =3D>
45 },
);
#relationship to find all old index statuses:
__PACKAGE__->has_many(
"old_statuses"=3D>"MyApp::IndexStatus",
{ "foreign.myindex" =3D> "self.myoldindex"},
);
----
then (in Cat app)
$c->model('MyApp::IndexStatus')-search_related('old_statuses');
produces SQL something like:
SELECT me.myindex, me.myoldindex, me.mystatus FROM index_statuses me JOIN
index_statuses old_statuses ON old_statuses.myindex =3D me.myoldindex:
even adding {join_type=3D>'LEFT'} to the arguments of has_many does not
produce a left join.
DBIx::Class has been pretty robust, I'm assuming that this is an
undocumented feature rather than a bug. However how can I get it to do a
left join?
Thanks in advance
Stephen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20130618/75d=
2d28c/attachment.htm
More information about the DBIx-Class
mailing list