Publishing multiple items with children to DB

I used the code from Publishing multiple rows to DB - many to many / one to many relationship and DB Action binding in database publishing

Which seems to work sometimes. The issue I’ve run into however is with multiple items. The parent table gets filled correctly but the child table does not.

So here’s the scenario:
I have 4 items, each with several child items inserted into slots. During the previewing of the DB template on each item, everything looks good. If I preview the content list, it looks good, if I preview the content list and the individual items, it looks good.

If I run my DB publish edition on the individual items (i.e. item one with child items only), it publishes out fine. However, when all items are in public state and I run the DB publishing to publish all, the parent items all publish, but not all the child items are publishing out. I hope that makes sense.

Thoughts anyone??

Shane

p.s. I posted this question in one of the above threads as well but didn’t receive any response, just thought maybe no one seen it, sorry for the duplicates. If this thread as the response then I’ll put that in the above thread.

Oh I just discovered, this only seems to do it with child items that are used by different parent items. So example I have Parent One that uses 3 child items (in the slot), I have parent two that uses the same 3 child items in its slot.

Looks like the last one published, gets the childern.

This sounds like a problem with your child-table key definition in your db publishing template. Try making the child-table’s key definition include both the parent id and the child id fields.

Sam is absolutely correct.
It seems like your child_id is set as primary key, however it is not and as such is being overwritten by the last item published with this id.
Set your keys to be unique as parent_id, child_id

Mike

That would make sense. I tried using the SEQ column referred to in the implementation guide with $rx.db.sequence(0,1) but of course it creates the same sequence for each parent, so only the last one is published, so that makes sense to me.

I tried doing the following:

$sys.item.getProperty(“rx:sys_contentid”) + $user.psoSlotTools.getSlotPropertyValues($slotcontent,“rx:sys_contentid”)

But it gives me a Long coercion exception which I have not idea what that is. I’ve used bindings in the past that have combined values, so I don’t understand what this means.

You need to make this change in the table definition, not in the bindings… you had the bindings correct before.

Your child table definition should include something like:


      <primarykey action="n">
         <name>PARENT_ID</name>
         <name>CHILD_ID</name>
      </primarykey>

Thanks for the suggestion Sam. I had actually just tried that before I got your suggestion and it seemed to work.

Thanks everyone.

Shane