Try putting the cascade="all, delete, delete-orphan" on OneToMany side of
the Relationship.
On Wed, Aug 27, 2008 at 9:05 AM, Michael Bayer <[EMAIL PROTECTED]>wrote:
>
>
> On Aug 26, 2008, at 6:08 PM, Alex Mathieu wrote:
>
> > Let's say I have two classes:
> >
> > class PublicationElement(Entity):
> > using_options(tablename='publication')
> > sections = OneToMany('SectionElement')
> > covers = OneToMany('PublicationCoverElement')
> > publication_id = Field(Integer, primary_key=True)
> > name = Field(Unicode(255))
> > short_name = Field(Unicode(30))
> > app_download_link = Field(UnicodeText)
> >
> > class SectionElement(Entity):
> > using_options(tablename='section')
> > publication = ManyToOne('PublicationElement',
> > colname="publication_id", cascade="all,delete-orphan")
> > section_id = Field(Integer, primary_key=True)
> > name = Field(Unicode(255))
> > articles_on_cover = Field(Integer)
> > articles_on_sub_cover = Field(Integer)
> > ad_on_top = Field(Boolean)
> > ad_on_bottom = Field(Boolean)
> > poll_rate_minutes = Field(Integer)
> > poll_weight = Field(Integer)
> > show_sub_cover = Field(Boolean)
> >
> > If I delete a PublicationElement entity, all the related
> > SectionElement entities get their publication_id key set to 0... and I
> > just can't figure it out why. I've been digging through the web, but
> > wasn't able any answer... Maybe I putted my cascade argument at the
> > wrong place ? Not sure to get it...
>
> this mapping suggests that the deletion of a SectionElement will cause
> the deletion of a related PublicationElement, but not the other way
> around. The cascade would have to be moved to the
> "PublicationElement.sections" side of the relation. Im not sure
> where the "0" is coming from, SQLAlchemy will normally set foreign key
> references to NULL if no row is related.
>
> >
>
--
Regards,
Harish
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---