﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
16356	Relationships in Django does not allow CASCADE delete	eguevara2012@…	nobody	"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."	Bug	closed	Database layer (models, ORM)	1.3	Normal	invalid	relationship		Unreviewed	0	0	0	0	0	0
