[apologies if anyone gets this for a second time]
Hello,
First of all, Michael, BIG "thank you" for an amazing piece of software!
I am relatively new to SQLAlchemy (so please forgive any n00b stupidity) -- I
use for two months with no issue until now. My problem is: I have a classic
one-to-many relationship: CbRecord being the parent and having many CbPersons.
The CbPerson primary key consists of two fields -- permalink and domain, the
second being the foreign key of the above-mentioned relationship at the same
time. The relevant code follows:
Base = declarative_base()
class CbRecord(Base, Cacheable):
__tablename__ = 'cb_record'
domain = Column(String(32), primary_key=True)
permalink = Column(String(48), nullable=False)
name = Column(String(16))
persons = relation(CbPerson, backref='parent', cascade="all, delete,
delete-orphan")
class CbPerson(Base):
__tablename__ = 'cb_persons'
permalink = Column(String(48), primary_key=True)
domain = Column(String(32), ForeignKey('cb_record.domain'),
primary_key=True)
title = Column(String(128))
first_name = Column(String(32))
last_name = Column(String(32))
Now when the database is empty, I can create these objects with no issue. When
running my tests a second tine however I get this error:
"FlushError: Instance <CbPerson at 0x10a3930> is an unsaved, pending instance
and is an orphan (is not attached to any parent 'CbRecord' instance via that
classes' 'persons' attribute)"
The code the error is rasied by is:
def _storeProfileToCache(self, profile):
# this creates the object in memory, out of a dictionary:
newRecord = CbRecord.createFromJsonDict(self.site, profile)
# this gets a SA session:
sess = OrmManager().newSession()
cbRecord = sess.merge(newRecord)
cbRecord.modified = None # a timestamp field that must be updated
sess.commit()
sess.close()
The sess.merge() call raises that error. The test that fails tries to merge a
CbRecord with five persons, two of which are identical to those in the database
(same primary key). I would expect the result to be the database having the
five persons stored and related to the same CbRecord.
I tried to read the FAQ and googled a lot but I could not figure out what's
wrong here. Any help would be highly appreciated.
Thanks in advance!
Yassen
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---