[sqlalchemy] Re: deletes using association_proxy

2009-06-03 Thread Michael Bayer

hollister wrote:


 # mappers
 mapper(Keyphrase, keyphrase_table)
 mapper(Action, action_table)

 mapper(KeyphraseAction, keyphrase_action_table, properties={
 'keyphrase': relation(Keyphrase,
 backref = 'keyphrase_action'),
 'action': relation(Action),
 })

 # test
 for i, action in enumerate(kp.actions):
 print action.action_name
 kp.actions.remove(action)   # this fails!

 s.commit()

you need to configure cascade so that SQLA knows to delete a
KeyphraseAction when it is deassociated from a Keyphrase.  See the mapping
docs for information on delete cascade.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: deletes using association_proxy

2009-06-03 Thread Hollister

Mike, thanks for the quick reply.
I suspected it was a cascade issue, and have been through the docs and
tried various configs. At the risk of appearing stupid, can you point
me in the right direction? Do the cascades only need to be on the
association table, or also on the left  right parent tables? If a
parent (Keyphrase or Action) is deleted, then I want the delete to
cascade to the association (KeyphraseAction), but not vice versa.

On Jun 3, 10:26 am, Michael Bayer mike...@zzzcomputing.com wrote:
 hollister wrote:

  # mappers
  mapper(Keyphrase, keyphrase_table)
  mapper(Action, action_table)

  mapper(KeyphraseAction, keyphrase_action_table, properties={
          'keyphrase': relation(Keyphrase,
              backref = 'keyphrase_action'),
          'action': relation(Action),
      })

  # test
  for i, action in enumerate(kp.actions):
      print action.action_name
      kp.actions.remove(action)   # this fails!

  s.commit()

 you need to configure cascade so that SQLA knows to delete a
 KeyphraseAction when it is deassociated from a Keyphrase.  See the mapping
 docs for information on delete cascade.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: deletes using association_proxy

2009-06-03 Thread Michael Bayer

cascades work from the parent that is being deleted or is having a child
removed to the child that is dependent on being attached to its parent.

so in this case Keyphrase-KeyphraseAction and Action-KeyPhraseAction
both in theory need delete, delete-orphan cascade.

In addition you can specify cascades in the database too in your foreign
keys by adding ON UPDATE DELETE to your ForeignKey entries (assuming you
are creating the schema with your table definitions).



Hollister wrote:

 Mike, thanks for the quick reply.
 I suspected it was a cascade issue, and have been through the docs and
 tried various configs. At the risk of appearing stupid, can you point
 me in the right direction? Do the cascades only need to be on the
 association table, or also on the left  right parent tables? If a
 parent (Keyphrase or Action) is deleted, then I want the delete to
 cascade to the association (KeyphraseAction), but not vice versa.

 On Jun 3, 10:26 am, Michael Bayer mike...@zzzcomputing.com wrote:
 hollister wrote:

  # mappers
  mapper(Keyphrase, keyphrase_table)
  mapper(Action, action_table)

  mapper(KeyphraseAction, keyphrase_action_table, properties={
          'keyphrase': relation(Keyphrase,
              backref = 'keyphrase_action'),
          'action': relation(Action),
      })

  # test
  for i, action in enumerate(kp.actions):
      print action.action_name
      kp.actions.remove(action)   # this fails!

  s.commit()

 you need to configure cascade so that SQLA knows to delete a
 KeyphraseAction when it is deassociated from a Keyphrase.  See the
 mapping
 docs for information on delete cascade.
 



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---