Werner F. Bruhin wrote:
> I have some items which are related but I need to change it so they
> related to another item.
>
> Before getting myself in a mess (as I need to do this for a bunch of
> tables) I wanted to check if the following approach is fine.
>
> I am using SA 0.5, ORM and declarative and the model is:
>
> class Cbbottle(Base):
> __table__ = sa.Table(u'cbbottle', metadata,
> sa.Column(u'cbbottleid', sa.Integer(),
> sa.Sequence('gen_cbbottle_cbbottleid'), primary_key=True, nullable=False),
> etc
> )
>
> purchase = sao.relation('Purchase', cascade="all, delete,
> delete-orphan", backref='cbbottle')
>
> aItem = session.query(db.Cbbottle).get(keyno)
> bItem = session.query(db.Cbbottle).get(anotherkeyno)
>
> for purchase in aItem.purchase:
> purchase.cbbottle = bItem
>
> session.commit()
>
> At this point I expect that aItem has no more "purchase" relations and
> they are all related to bItem.
>
>
I had a go at it and get this error on a few tables:
c:\python25\lib\site-packages\sqlalchemy-0.5.2-py2.5.egg\sqlalchemy\orm\properties.py:711:
SAWarning: On Bottag.bothist, delete-orphan cascade is not supported on
a many-to-many or many-to-one relationship when single_parent is not
set. Set single_parent=True on the relation().
self._determine_direction()
Changing the relations then makes it run without error but there is one
record being missed.
I changed it slightly:
aItem = session.query(db.Cbbottle).get(keyno)
bItem = session.query(db.Cbbottle).get(anotherkeyno)
for purchase in aItem.purchase:
purchase.cbbottle = bItem
purchase.fk_cbbottleid = bItem.cbbottleid
session.commit()
But for some reason one record is still not reassigned. So, what I do
is obviously not quit right.
Werner
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---