[Django] #16356: Relationships in Django does not allow CASCADE delete

4 views
Skip to first unread message

Django

unread,
Jun 26, 2011, 10:55:52 PM6/26/11
to django-...@googlegroups.com
#16356: Relationships in Django does not allow CASCADE delete
----------------------------+----------------------------------------------
Reporter: eguevara2012@… | Owner: nobody
Type: Bug | Status: new
Milestone: | Component: Database layer (models, ORM)
Version: 1.3 | Severity: Normal
Keywords: relationship | Triage Stage: Unreviewed
Has patch: 0 | Easy pickings: 0
UI/UX: 0 |
----------------------------+----------------------------------------------
Hello!
I've been through this ticket alert that Django relationships are wrong.
A simple example:
An owner has an address.
A house has an address.

The classes would be:

class Owner(models.Model):
address = models.ForeignKey(Address)
#or better
# address = models.OneToOneField(Address)

class House(models.Model):
address = models.ForeignKey(Address)
#or better
# address = models.OneToOneField(Address)

class Address(models.Model):
street = models.CharField(max_length=100)
number = models.IntegerField(default=0)


This is the correct mapping following the logic of object-orientation, but
this mapping does not allow remove related objects by CASCADE.
According to the Django doc, the mapping is inverse:

class Owner(models.Model):
#other fields

class House(models.Model):
#other fields

class Adress(models.Model):
street = models.CharField(max_length=100)
number = models.IntegerField(default=0)
owner = models.ForeignKey(Owner)
house = models.ForeignKey(House)


The big problem is that this mapping in the form of owner the address form
is shown with a select of houses, and in the form of owner is shown a form
address with a select of owners.
Look, I want to register an owner and his address, this is end of the
registration.
After i want register a house, register your address and there can select
the owner to associate home with owner.

I urge to carefully read the Hibernate reference manual to understand how
relationships should be made in Django:

http://docs.jboss.org/hibernate/annotations/3.5/reference/en/html/entity.html
#entity-mapping-association

I would like to examine this problem because i can not remove an owner and
remove the house and address by CASCADE, and remove a house and its
address by CASCADE using my firts example for mapping class.

Regards.

--
Ticket URL: <https://code.djangoproject.com/ticket/16356>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 27, 2011, 2:09:48 AM6/27/11
to django-...@googlegroups.com
#16356: Relationships in Django does not allow CASCADE delete
-------------------------------------+-------------------------------------
Reporter: | Owner: nobody
eguevara2012@… | Status: closed
Type: Bug | Component: Database layer
Milestone: | (models, ORM)
Version: 1.3 | Severity: Normal
Resolution: invalid | Keywords: relationship
Triage Stage: | Has patch: 0
Unreviewed | Needs tests: 0
Needs documentation: 0 | Easy pickings: 0
Patch needs improvement: 0 |
UI/UX: 0 |
-------------------------------------+-------------------------------------
Changes (by aaugustin):

* status: new => closed
* needs_docs: => 0
* resolution: => invalid
* needs_tests: => 0
* needs_better_patch: => 0


Comment:

I urge you to read Django's documentation to understand how Django works
and clear any confusion with other frameworks :)

More seriously, you have 1-to-1 relations, so you can put the Foreign Key
in either model. Depending on the side of the relation where you put the
foreign, deletes will cascade or not. This is a SQL modeling issue, it
isn't particularly related to Django.

This tracker is appropriate to report bugs in Django. "Django doesn't work
like Hibernate" isn't a bug. For general usage questions, please join
#django on !FreeNode or post to the django-users mailing list.

--
Ticket URL: <https://code.djangoproject.com/ticket/16356#comment:1>

Django

unread,
Sep 26, 2016, 11:21:34 AM9/26/16
to django-...@googlegroups.com
#16356: Relationships in Django does not allow CASCADE delete
-------------------------------------+-------------------------------------
Reporter: eguevara2012@… | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 1.3
(models, ORM) |
Severity: Normal | Resolution: invalid

Keywords: relationship | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Tim Graham:

Old description:

New description:

class House(models.Model):
#other fields

http://docs.jboss.org/hibernate/annotations/3.5/reference/en/html/entity.html
#entity-mapping-association

Regards.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/16356#comment:2>

Reply all
Reply to author
Forward
0 new messages