[Catalyst] DBIx::Class method, "update_or_create_related" - it tries to populate the primary key value of the related object

kakimoto at tpg.com.au kakimoto at tpg.com.au
Tue Aug 19 01:43:17 BST 2008


Hello, there, Zbigniew,

   Thanks for the article, "Perl Alchemy - notes of a Catalyst programmer".
Phew.. Thought I was going insane cause I figured a proper ORM would not
have this problem.


  Anyway, can you please give some examples of using pk => undef?
The code extract below is what I used and doesn't work.


1:         $agents->update_or_create_related(
2:            'home_loan',
3:            $self->get_loan_related_data($c),
4:            { pk => 'undef' }
5:         );

Line 4 is what I fed in.. If you could so kindly provide some example,
it would be really helpful.
Thank you:)



K. akimoto
'kuruma nihon wa totemo genki;)'


<---------------------------------------------------------------------------->



Quoting Zbigniew Lukasiak <zzbbyy at gmail.com>:

> Hmm,
> 
> Maybe this:
> http://perlalchemy.blogspot.com/2008/06/dbixclass-gotchas.html
> - would be a better intro into the subject.
> 
> Z.
> 
> On Mon, Aug 18, 2008 at 3:20 PM, Zbigniew Lukasiak <zzbbyy at gmail.com>
> wrote:
> > On Mon, Aug 18, 2008 at 2:56 PM,  <kakimoto at tpg.com.au> wrote:
> >>
> >> hello, all,
> >>
> >>  I am trying to use DBIx::Class method, "update_or_create_related"
> to
> >> cut down the amount of code I have. My code has happily worked
> with
> >>
> >> 1) me manually doing a search (with "find") to see if an object
> in
> >> question exists or not. If it doesn't, I will issue a
> "new"/"create" .
> >> Else, the "find" will give out the object, I perform whatever I
> need to
> >> perform on the attributes and update it.
> >>
> >> 2) the database table of the related object has a nice sequence
> set up
> >> for its primary key, "ID".
> >>
> >> Now, when I tried to use "update_or_create_related", the code
> actually
> >> produces an error for which the "ID" attribute in the SQL for
> INSERT is
> >> null and hence, cannot be inserted to the database engine for
> reason
> >> that a primary key attribute value can never be NULL.
> >>
> >>  It's fair up there but I just do not know why is DBIX::Class
> even
> >> bothering to put the primary key value, ID into the dynamic SQL
> that it
> >> uses to insert the entry into the database when there's already a
> >> sequence declared for it....
> >>
> >
> >
> > It's a long story - you might have a look at:
> >
> http://lists.scsys.co.uk/pipermail/dbix-class/2008-June/thread.html#6403
> > to see some discussion about it.  I also posted some code for a
> > DBIx::Class "plugin" with a modified update_or_create_related
> method
> > (which should work for you and additionaly it allows for recursive
> > updating the database).  It is not really polished code - it
> requires
> > some name changes - but it has test :)
> >
> > By the way - there is a separate DBIC mailing list (see the link
> > above) where you should direct emails in thit subject.
> >
> > --
> > Zbigniew Lukasiak
> > http://brudnopis.blogspot.com/
> > http://perlalchemy.blogspot.com/
> >
> 
> 
> 
> -- 
> Zbigniew Lukasiak
> http://brudnopis.blogspot.com/
> http://perlalchemy.blogspot.com/
> 
> _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive:
> http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/
> 
> 
> 





More information about the Catalyst mailing list