[Dbix-class] Unable to chain resultset method on a many_to_many relationship method

Michael Blanco blanco217 at gmail.com
Mon Oct 26 21:36:28 GMT 2009


Try using the following

current_source_alias

http://search.cpan.org/~ribasushi/DBIx-Class-0.08112/lib/DBIx/Class/ResultS=
et.pm

----------------------------
Michael Blanco




On Mon, Oct 26, 2009 at 12:19 PM, Anthony Gladdish <
a.j.gladdish at newcastle.ac.uk> wrote:

> Hi all,
>
> I have the following tables and relationships:
>
> Module --< ModuleTag >-- Tag
>
> MyApp::Result::Module:
>
> __PACKAGE__->has_many( 'module_tags' =3D> ' MyApp::Result::ModuleTag',
> 'module' );
> __PACKAGE__->many_to_many('tags' =3D> 'module_tags', 'tag' );
>
> MyApp::Result::Tag:
>
> __PACKAGE__->has_many( 'tag_modules' =3D> 'MyApp::Result::ModuleTag', 'ta=
g'
> );
> __PACKAGE__->many_to_many('modules' =3D> 'tag_modules', 'module' );
>
> MyApp::Result::ModuleTag:
>
> __PACKAGE__->belongs_to( tag =3D> ' MyApp::Result::Tag', 'tag' );
> __PACKAGE__->belongs_to( module =3D> ' MyApp::Result::Module', 'module' );
>
> MyApp::ResultSet::Tag:
>
> sub weightings {
>    my $self =3D shift;
>    return $self->search_rs(
>                {},
>                {
>                        join     =3D> 'tag_modules',
>                      select   =3D> [ 'me.id', 'me.name', { count =3D>
> 'tag_modules.tag' } ],
>                        as       =3D> [qw/ id name weighting  /],
>                        group_by =3D> 'me.name',
>                }
>        );
> }
>
> Test cases:
>
> # 1:
> $schema->resultset('Tag')->weightings();
>
> ... this does what I expect and returns correct results and following sql:
> # SELECT me.id, me.name, COUNT( tag_modules.tag )
> # FROM Tag me LEFT JOIN Module_Tag tag_modules ON tag_modules.tag =3D me.=
id
> # GROUP BY me.name
>
> # 2:
> $module1->tags->weightings();
>
> ... this dies producing error:
>
> no such column: me.name [for Statement "SELECT me.id, me.name, COUNT(
> tag_modules.tag ) FROM Module_Tag me JOIN Tag tag ON tag.id =3D me.tag LE=
FT
> JOIN Module_Tag tag_modules ON tag_modules.tag =3D tag.id WHERE ( me.modu=
le
> =3D ? ) GROUP BY me.name"]
>
> I was expecting this resultset chaining to work. I'm not sure if I'm
> missing a trick here in my aliases, or if this should be possible or if I=
'm
> doing it wrong.
> Anybody have any suggestions?
>
> Thanks,
> Anthony
>
> _______________________________________________
> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> Searchable Archive:
> http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20091026/371=
d0b7b/attachment.htm


More information about the DBIx-Class mailing list