[Dbix-class] SQL error under 0.08108 or higher

Carl Franks fireartist at gmail.com
Mon Aug 31 13:31:57 GMT 2009


I've got some code that's started throwing an exception after
ugprading DBIx-Class from 0.08107 to 0.08108 or higher.

The error only occurs under MySQL (v3.23.49) - it runs without error
using SQLite.

Under 0.08107, the generated SQL used an explicit LEFT JOIN:
SELECT COUNT( * ) FROM group_rel me LEFT JOIN groups groups ON
groups.id = me.group_id WHERE ( me.parent_id = ? ): '1'

Under 0.08108 and above, the type of join isn't specified, causing the
following error:
DBIx::Class::ResultSet::count(): DBI Exception: DBD::mysql::st execute
failed: You have an error in your SQL syntax near 'ON groups.id =
me.group_id WHERE ( me.parent_id = '1' )' at line 1 [for Statement
"SELECT COUNT( * ) FROM group_rel me JOIN groups groups ON groups.id =
me.group_id WHERE ( me.parent_id = ? )" with ParamValues: 0='1']

The code I am running is:

$group->search_related( 'child_rel' )
    ->search_related( 'groups' )
    ->count;

Is there a problem with the relationships I have defined?
My two relevant package definitions are:

package CMS::Schema::Group;

__PACKAGE__->add_columns(
    "id",
    {
        data_type     => "INTEGER",
        is_nullable   => 0,
        is_auto_increment => 1,
    },
    "name",
    {   data_type     => "VARCHAR",
        is_nullable   => 0,
    },
);

__PACKAGE__->has_many( child_rel => 'CMS::Schema::GroupRel', 'parent_id' );

###

package CMS::Schema::GroupRel;

__PACKAGE__->add_columns(
    "group_id",
    {
        data_type     => "INTEGER",
        is_nullable   => 0,
    },
    "parent_id",
    {
        data_type     => "INTEGER",
        is_nullable   => 0,
    },
);

__PACKAGE__->has_many( groups => 'CMS::Schema::Group', 'id' );



More information about the DBIx-Class mailing list