ORM one-to-many cascade="none"

54 views
Skip to first unread message

David Sedeño

unread,
Jun 2, 2015, 4:34:08 AM6/2/15
to lu...@googlegroups.com
Hi,

I'm trying to use an one-to-many relation with the cascade="none" option it won't delete the childs objects, but it seems to not work, it puts the pk key to null in the child table.

It's this option correctly supported or I'm missing something ?

Lucee Vers. 4.5.1.0

Thanks
---
David Sedeño

Nando Breiter

unread,
Jun 2, 2015, 11:39:43 AM6/2/15
to lu...@googlegroups.com
David,

What would you expect it to do if cascade="none" when the parent entity is deleted? 

Are you really saying that it sets the primary key on the child row to null? 

Maybe it would help if you show some detail of your configuration and state clearly what happens when a parent object is deleted.



Aria Media Sagl
Via Rompada 40
6987 Caslano
Switzerland

+41 (0)91 600 9601
+41 (0)76 303 4477 cell
skype: ariamedia

--
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/d2389917-4ea0-4096-890c-d9c8fe9a18e6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

David Sedeño

unread,
Jun 2, 2015, 11:52:49 AM6/2/15
to lu...@googlegroups.com
Hi Nando,


2015-06-02 17:39 GMT+02:00 Nando Breiter <na...@aria-media.com>:
David,

What would you expect it to do if cascade="none" when the parent entity is deleted? 

Well, in the "Building Applications with Coldfusion ORM" book it says:

  "setting the cascade option to ' none ' and ColdFusion will not automatically update any other records in the database."

So, I expect to hibernate not update the 'child' record at all.
 

Are you really saying that it sets the primary key on the child row to null? 

No, in the Child table, the parent_id is set to null when the parent is deleted.

Maybe it would help if you show some detail of your configuration and state clearly what happens when a parent object is deleted.


Parent.cfc:

  property name="child" fieldtype="one-to-many"  fkcolumn="parent_id" cascade="none";


If I delete a 'parent' object, I expect to childs rows stay with the parent_id as it was but hibernate set it to null.

Regards,
---
David Sedeño
 



Aria Media Sagl
Via Rompada 40
6987 Caslano
Switzerland

+41 (0)91 600 9601
+41 (0)76 303 4477 cell
skype: ariamedia

On Tue, Jun 2, 2015 at 10:34 AM, David Sedeño <tco...@gmail.com> wrote:
Hi,

I'm trying to use an one-to-many relation with the cascade="none" option it won't delete the childs objects, but it seems to not work, it puts the pk key to null in the child table.

It's this option correctly supported or I'm missing something ?

Lucee Vers. 4.5.1.0

Thanks
---
David Sedeño

--
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/d2389917-4ea0-4096-890c-d9c8fe9a18e6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Lucee" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/lucee/8iOLar3Embs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to lucee+un...@googlegroups.com.

To post to this group, send email to lu...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
David Sedeño Fernández
Zoconet SL
Tel. 657 384 329

Nando Breiter

unread,
Jun 2, 2015, 12:19:20 PM6/2/15
to lu...@googlegroups.com
Well, my interpretation is that the documentation is wrong, the behavior is understandable and seems correct to me, because it cleans up a reference that is no longer valid. 

If you really want the reference to the parent to remain for some reason when the parent is deleted, then perhaps using a "soft delete" on the parent would solve the issue? By soft delete I mean add a field to the parent "isDeleted" and set that to true if the record is to be deleted (and don't show isDeleted records to your users, of course). 



Aria Media Sagl
Via Rompada 40
6987 Caslano
Switzerland

+41 (0)91 600 9601
+41 (0)76 303 4477 cell
skype: ariamedia

Mark Drew

unread,
Jun 2, 2015, 12:27:37 PM6/2/15
to lu...@googlegroups.com
This behaviour, even though odd feels *right*

What would happen if you now create another Parent object, that now happens to have the same ID as the deleted object? All the children are now assigned to it. So maybe removing the parent_id *IS* the right behaviour so you don’t get really odd (and dangerous) behaviours… 


Mark Drew


develop • deploy • deliver
http://charliemikedelta.com

Chris Blackwell

unread,
Jun 2, 2015, 1:02:27 PM6/2/15
to lu...@googlegroups.com

Unless you set the child's parent_I'd to null you can't delete the parent, the constraint wouldn't let you.

So the behaviour is correct, docs need sorting


Julian Halliwell

unread,
Jun 3, 2015, 3:52:22 AM6/3/15
to lu...@googlegroups.com
Try adding the inverse attribute to the child property in your parent entity:

property name="child" cfc="child" fieldtype="one-to-many"
fkcolumn="parent_id" cascade="none" inverse="true";

David Sedeño

unread,
Jun 3, 2015, 10:54:30 AM6/3/15
to lu...@googlegroups.com
Hi Julian,

cascade="none" inverse="true";

that did what I want!

Thanks!
---
David Sedeño



--
You received this message because you are subscribed to a topic in the Google Groups "Lucee" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/lucee/8iOLar3Embs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages