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

Zbigniew Lukasiak zzbbyy at gmail.com
Mon Aug 18 14:41:57 BST 2008


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/



More information about the Catalyst mailing list