[Dbix-class] INSERT occurring on SELECT

Jonathan Rockway jon at jrock.us
Mon Jun 30 06:31:06 BST 2008


* On Tue, Jun 24 2008, Dermot wrote:
> Hi,
>
> I have been trying to get started using dbix (in a Catalyst env) and
> have hit an early problem. When I call a method to list all the
> entries in one table, null entries are created in a different table.
> Below is the trace.
>
> SELECT me.id, me.name, me.contrib_id FROM submissions me:
> SELECT me.id, me.name, me.contrib_id FROM submissions me:
> SELECT me.id, me.code FROM contributors me WHERE ( ( ( me.id = ? ) ) ): '1'
> SELECT me.id, me.code FROM contributors me WHERE ( ( ( me.id = ? ) ) ): '2'
> INSERT INTO contributors (id) VALUES (?): '2'
> SELECT me.id, me.code FROM contributors me WHERE ( ( ( me.id = ? ) ) ): '3'
> INSERT INTO contributors (id) VALUES (?): '3'
>
>
> I have a small dataset. There are 2 tables. T1 has with a single entry.
>>sqlite3 motion.db "select * from contributors"
> 1|S6G
>
> T2 have 3 entries. The 3rd column is the ID in T1.
>>sqlite3 motion.db "select * from submissions"
> 1|23|1
> 2|167|1
> 3|254|1
>
> If I use a conventional script to list the data, all is fine.
>
> I have traced the problem to my Template within my Catalyst app.
>
>    [% FOREACH submission IN submissions %]
>    [%# SET contributor = submission.contrib_id %]
>   <li>
>     [% submission.name | html %]&nbsp;[%# contributor.code | html
> %]&nbsp;[%# submission.contrib_id.code %]
>
> If any of the commented lines are used I get the result below.
>
>>sqlite3 motion.db "select * from contributors"
> 1|S6G
> 2|
> 3|
>
> I hope this isn't OT for the list. Can anyone suggest where the
> problem might be?

Can you boil this down to a pure Perl test case?  There is really too
much going on in your template to know what could be causing the insert.
(Basically, you have three things commented out, not all related.  I
don't feel like manually testing each case.)

If you can narrow it down to one line of Perl that causes the problem,
then we can help you.

Using a minimal schema would also be helpful, but probably not necessary
quite yet.  I think I can guess what your schema looks like.

Regards,
Jonathan Rockway

-- 
print just => another => perl => hacker => if $,=$"



More information about the DBIx-Class mailing list