Re: [Dbix-class] Problem overriding connection method from Schema module
Original Message Subject: Re: [Dbix-class] Problem overriding connection method from Schema module Date: Mon, 24 Aug 2009 09:23:06 +0200 From: Emmanuel Quevillon t...@pasteur.fr Reply-To: t...@pasteur.fr Organization: Institut Pasteur To: Byron Young byron.yo...@riverbed.com CC: 'DBIx::Class user and developer list' dbix-class@lists.scsys.co.uk, DBIx:@ Class useranddeveloperlistdbix-class@lists.scsys.co.uk References: 4a8e6204.6090...@pasteur.fr afd6dc5f1927784d91384a975995d33b0198d6114...@mailboxes.nbttech.com Byron Young wrote: Emmanuel Quevillon wrote on 2009-08-21: sub connection { my ($self, @rest) = @_; $self-next::method(@rest); $self-driver_name($self-handler()-{Driver}-{Name}); } # You can replace this text with custom content, and it will be preserved on regeneration 1; Hey Emmanuel, connection() must return the schema object (which will be returned by $self-next::method(@rest)). In this case it will actually return the driver name string instead, which explains why the interpreter chokes when it tries to call the resultset() method on a string, as in your error below. Hi Byron, Thanks to pointing me to this. It makes a lot of sense! I fixed it and it works like a charm both from my scripts and from my Catalyst App. my $schema = Schema::MyAppDB-connect('dib:Pg:dbname=test','test','pass'); my $a = $schema-resultset(Public); I get the following error Can't locate object method resultset via package Pg (perhaps you forgot to load Pg?) at ./test.pl line 7. The Catalyst cookbook section is incorrect - it would be great for you to supply a doc patch to the catalyst list so other people don't run into this as well. Byron Emmanuel -- - Emmanuel Quevillon Biological Software and Databases Group Institut Pasteur +33 1 44 38 95 98 tuco at_ pasteur dot fr - -- - Emmanuel Quevillon Biological Software and Databases Group Institut Pasteur +33 1 44 38 95 98 tuco at_ pasteur dot fr - ___ 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
Re: [Dbix-class] Problem overriding connection method from Schema module
Byron Young wrote: Emmanuel Quevillon wrote on 2009-08-21: sub connection { my ($self, @rest) = @_; $self-next::method(@rest); $self-driver_name($self-handler()-{Driver}-{Name}); } # You can replace this text with custom content, and it will be preserved on regeneration 1; Hey Emmanuel, connection() must return the schema object (which will be returned by $self-next::method(@rest)). In this case it will actually return the driver name string instead, which explains why the interpreter chokes when it tries to call the resultset() method on a string, as in your error below. Hi Byron, Thanks to pointing me to this. It makes a lot of sense! I fixed it and it works like a charm both from my scripts and from my Catalyst App. my $schema = Schema::MyAppDB-connect('dib:Pg:dbname=test','test','pass'); my $a = $schema-resultset(Public); I get the following error Can't locate object method resultset via package Pg (perhaps you forgot to load Pg?) at ./test.pl line 7. The Catalyst cookbook section is incorrect - it would be great for you to supply a doc patch to the catalyst list so other people don't run into this as well. Byron Emmanuel -- - Emmanuel Quevillon Biological Software and Databases Group Institut Pasteur +33 1 44 38 95 98 tuco at_ pasteur dot fr - ___ 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
Re: [Dbix-class] different query after upgrade
Actually, never mind what i just said. DBIC is right, it's a proper bugfix. *Generally*, it is not correct to LEFT JOIN one thing then JOIN onwards from it, which clearly is not your case here. Sorry for the wrong spot. -- wallace reis/wreis Catalyst and DBIx::Class consultancy with a clue Software Developer and a commit bit: http://shadowcat.co.uk/catalyst/ Shadowcat Systems Limited http://www.shadowcat.co.uk http://www.linkedin.com/in/wallacereis ___ 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
[Dbix-class] have add_to_$rel return $link for many to many
Hello, I'd like add_to_$rel return the $link instead of $obj in ::ManyToMany.pm. I've inlined a diff below that does so, with an updated test and documentation patch against http://dev.catalyst.perl.org/repos/bast/DBIx-Class/0.08/tags/0.08109 Index: t/relationship/core.t === --- t/relationship/core.t (revision 7380) +++ t/relationship/core.t (working copy) @@ -9,7 +9,7 @@ my $schema = DBICTest-init_schema(); my $sdebug = $schema-storage-debug; -plan tests = 79; +plan tests = 80; # has_a test my $cd = $schema-resultset(CD)-find(4); @@ -185,7 +185,10 @@ my $prod_before_count = $schema-resultset('Producer')-count; is( $prod_rs-count, 0, CD doesn't yet have any producers ); my $prod = $schema-resultset('Producer')-find(1); -$cd-add_to_producers($prod); +isa_ok( + $cd-add_to_producers($prod), + 'DBICTest::Schema::CD_to_Producer' = '$cd-add_to_producers($prod)' +); is( $prod_rs-count(), 1, 'many_to_many add_to_$rel($obj) count ok' ); is( $prod_rs-first-name, 'Matt S Trout', 'many_to_many add_to_$rel($obj) ok' ); Index: lib/DBIx/Class/Relationship/ManyToMany.pm === --- lib/DBIx/Class/Relationship/ManyToMany.pm (revision 7380) +++ lib/DBIx/Class/Relationship/ManyToMany.pm (working copy) @@ -102,7 +102,7 @@ my $link = $self-search_related($rel)-new_result($link_vals); $link-set_from_related($f_rel, $obj); $link-insert(); - return $obj; + return $link; }; my $set_meth_name = join '::', $class, $set_meth; Index: lib/DBIx/Class/Relationship.pm === --- lib/DBIx/Class/Relationship.pm (revision 7380) +++ lib/DBIx/Class/Relationship.pm (working copy) @@ -595,13 +595,14 @@ To add a role for your actor, and fill in the year of the role in the actor_roles table: - $actor-add_to_roles($role, { year = 1995 }); + my $link = $actor-add_to_roles($role, { year = 1995 }); In the above example, ActorRoles is the link table class, and Role is the foreign class. The C$link_rel_name parameter is the name of the accessor for the has_many relationship from this table to the link table, and the C$foreign_rel_name parameter is the accessor for the belongs_to relationship -from the link table to the foreign table. +from the link table to the foreign table. The My::DBIC::Schema::ActorRoles +instance is returned. To use many_to_many, existing relationships from the original table to the link table, and from the link table to the end table must already exist, these ___ 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