[Dbix-class] Can't get many_to_many links to work

Hartmaier Alexander alexander.hartmaier at t-systems.at
Thu Jan 30 11:24:15 GMT 2014


On 2014-01-29 21:38, Ekki Plicht (DF4OR) wrote:
> Hi,
> I have a hard time to get a many_to_many 'relation' to work.
>
> Three tables: Pages, Images and PageImg (the link or bridge table). A
> page contains many images, an image can appear on many pages.
>
> ########################################################
> # The page table
> package Bildzuo::Result::Page;
> [...]
> __PACKAGE__->has_many(
>   "page_imgs",
>   "Bildzuo::Result::PageImg",
>   { "foreign.page_id" => "self.id" },
>   { cascade_copy => 0, cascade_delete => 0 },
> );
>
> __PACKAGE__->many_to_many('images' => 'page_imgs', 'img');
>
> ########################################################
> # The image table
> package Bildzuo::Result::Img;
> [...]
> __PACKAGE__->has_many(
>   "page_imgs",
>   "Bildzuo::Result::PageImg",
>   { "foreign.img_id" => "self.id" },
>   { cascade_copy => 0, cascade_delete => 0 },
> );
>
> __PACKAGE__->many_to_many('pages' => 'page_imgs', 'page');
>
>
> ########################################################
> # The bridge table
> package Bildzuo::Result::PageImg;
> [...]
>
> __PACKAGE__->belongs_to(
>   "img",
>   "Bildzuo::Result::Img",
>   { id => "img_id" },
>   { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
> );
>
> __PACKAGE__->belongs_to(
>   "page",
>   "Bildzuo::Result::Page",
>   { id => "page_id" },
>   { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
> );
> ########################################################
>
> Regardless from which side I try to get a resultset, I always get the error
> Can't locate object method "images" via package "DBIx::Class::ResultSet"
> or
> Can't locate object method "pages" via package "DBIx::Class::ResultSet"
>
> Any idea what's wrong here? The result modules were generated by
> 'dbicdump', with the many to many bridges added manually.
>
>
> TIA,
> Ekki
Hi,
a resultset is a collection or result objects, a relationship is from a
single result object to 0 to n other result objects so you can only call
the generated methods on a result object, not a resultset.

As you didn't include the actual code that triggers the error messages
we can't give you further advise.

>
> _______________________________________________
> 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



*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
T-Systems Austria GesmbH Rennweg 97-99, 1030 Wien
Handelsgericht Wien, FN 79340b
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
Notice: This e-mail contains information that is confidential and may be privileged.
If you are not the intended recipient, please notify the sender and then
delete this e-mail immediately.
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*



More information about the DBIx-Class mailing list