I should note that I am using:
Python version 2.5.2
SQLAlchemy version 0.4.6
Elixir version 0.6.1


On Apr 9, 4:03 pm, mhearne808 <[email protected]> wrote:
> From reading through the Elixir and SQLAlchemy documentation, it seems
> that, by default, a foreign key in a table should be set to null once
> the row in the other table is deleted.  However, I can't seem to write
> code that demonstrates this behavior.  Basically, I am creating two
> "Persons", a mother and a child.  I'm deleting the mother, but the
> child seems to be holding on to the reference to his mother.  How do I
> tell the child his mother is dead? :)
>
> Code:
> ############################################
> from elixir import *
> import os.path
>
> class Person(Entity):
>     belongs_to('mom',of_kind='Person')
>     has_many('children',of_kind='Person')
>     has_field('name',Text)
>
> if __name__ == '__main__':
>     FNAME = 'test.sqlite'
>     DBFILE = "sqlite:///%s" % FNAME
>     metadata.bind = DBFILE
>     metadata.bind.echo = False
>     if os.path.isfile(FNAME):
>         os.remove(FNAME)
>     setup_all(True)
>
>     mom = Person(name='Mom')
>     bobby = Person(name='Bobby')
>     bobby.mom = mom
>     session.commit()
>     print 'Mom ID (according to Bobby), before deleting Mom: %i' %
> bobby.mom_id
>     session.delete(mom)
>     session.commit()
>     session.refresh(bobby)
>     print 'Mom ID (according to Bobby), after deleting Mom: %i' %
> bobby.mom_id
> ############################################
>
> Output:
> ############################################
> Mom ID (according to Bobby), before deleting Mom: 1
> Mom ID (according to Bobby), after deleting Mom: 1
> ############################################
--~--~---------~--~----~------------~-------~--~----~
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