Hi Graham,

thanks for all of this. Do you think you could dump me your database
skeleton ? Would save me quite of time... I'm looking forward eagerly
to run this code, though.

Also, I figured out yesterday that my foreign key values into my
tables couldn't be set to null, so I set to true the NULL possibility
into the database schema. However, didn't solved my problem (I thought
it might be related to my problem)... I still get the child's objects
to have their foreign key (to parent object) value setted to 0/NULL
when the parent is deleted. I tried yet again yesterday night playing
with the cascade stuff in all directions, always getting the key to be
set to 0 (or NULL now since I changed the DB schema).

Let me know if you can dump me the DB skeleton, else, I'll do it
manually.

Thanks a lot, once againg :)

+

Alex.

On Aug 27, 8:07 pm, Graham Higgins <[EMAIL PROTECTED]> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 27 Aug 2008, at 18:06, Graham Higgins wrote:
>
> I decided to investigate and the mist has cleared a little for me.
>
> > The 0.5 docs reiterate the warning:
>
> > "ON UPDATE and ON DELETE clauses to a table create are specified
> > within the ForeignKeyConstraint object, using the onupdate and
> > ondelete keyword arguments:
>
> The clauses specify that underlying db is to manage the cascade.
> Neither SQLite nor MySQL MyISAM tables support this.
>
> Alternatively, specifying the cascade="all,delete-orphan" option in a
> relation gives the responsibility of handling the cascade to SA ---
> and it manages splendidly with both SQLite and MySQL MyISAM tables, so
> you should be just fine.
>
> Here's a working example that you can elaborate upon:
>
> from elixir import *
>
> metadata.bind = 'sqlite:///:memory:'
> # metadata.bind = 'sqlite:///movies.sqlite'
> # metadata.bind = 'mysql://localhost/cascade_test'
> # metadata.bind.echo = True
>
> class Movie(Entity):
>      title = Field(Unicode(30), primary_key=True)
>      year = Field(Integer, primary_key=True)
>      description = Field(UnicodeText)
>      releasedate = Field(DateTime)
>
>      director = ManyToOne('Director')
>      genres = ManyToMany('Genre', cascade="all,delete-orphan")
>      actors = ManyToMany('Actor', tablename='movie_casting',
> cascade="all,delete-orphan")
>
>      def __repr__(self):
>          return '<Movie "%s" (%d)>' % (self.title, self.year)
>
> class Person(Entity):
>      using_options(inheritance='multi')
>
>      name = Field(Unicode(60))
>
>      def __repr__(self):
>          return '<Person "%s">' % self.name
>
> class Actor(Person):
>      using_options(inheritance='multi')
>
>      movies = ManyToMany('Movie', tablename='movie_casting')
>
>      def __repr__(self):
>          return '<Actor "%s">' % self.name
>
> class Director(Person):
>      using_options(inheritance='multi')
>
>      movies = OneToMany('Movie', cascade="all,delete-orphan")
>
>      def __repr__(self):
>          return '<Director "%s">' % self.name
>
> class Genre(Entity):
>      name = Field(Unicode(15), primary_key=True)
>
>      movies = ManyToMany('Movie')
>
>      def __repr__(self):
>          return '<Genre "%s">' % self.name
>
> setup_all()
> create_all()
>
> rscott = Director(name=u"Ridley Scott")
> glucas = Director(name=u"George Lucas")
> alien = Movie(title=u"Alien", year=1979)
> swars = Movie(title=u"Star Wars", year=1977)
> brunner = Movie(title=u"Blade Runner", year=1982)
> rscott.movies.append(brunner)
> rscott.movies.append(alien)
> swars.director = glucas
> print rscott.movies
> print session.query(Movie).filter_by(director=rscott).count()
> session.delete(rscott)
> print session.query(Movie).filter_by(director=rscott).count()
> session.commit()
>
> HTH
>
> Cheers,
>
> Graham
>
> -----BEGIN PGP SIGNATURE-----
>
> iEYEARECAAYFAki17FMACgkQOsmLt1Nhivz+8gCfYVESg40a34Kxj2MbMQZnSFh/
> 4tsAn1byfKmF2Qxv1OIDRiPx1sy3M9uciQCVAgUBSLXsU1nrWVZ7aXD1AQK+fAP6
> AlcHzhCcxuwYqTzgAcT9djdQBP4HI1cwB3NwTsG83LcnGoDIaht8B2Kxj5GDgaq6
> 4fPJJ4Olu/mWLRmlv8nTjiy4xRhLlvuStJoy3FYM4ZI9Z117VUGZTgp4aqOgIEt3
> akZrxaOdqcSX9KYJvBRgh9Ffkr9JCYu07vK9PCj4jWE=
> =dON4
> -----END PGP SIGNATURE-----
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"SQLElixir" 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/sqlelixir?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to