I added two properties to a mapper. One of the properties is from an
external table and the other is self-referential. If I update the
external property, SA picks up on the change. A save and flush
operation works fine. However, when I modify and subsequently
save/flush the self-referential property, SA does nothing.

Although, I used the syntax in the manual (and tried plenty of
variations), I cannot get it to work. Of course, I am sure that I did
something wrong. Can anyone spot my error?

# test sequence is below

class BranchTbl(object):
   pass  # other stuff omitted for brevity...

branches_table = Table('branches', metadata,
    Column('branchid', Integer, primary_key=True),
    Column('parent', Integer, ForeignKey('branches.branchid'),
nullable=True),
    Column('state', Integer, ForeignKey('enums.enumid'),
nullable=False)
   # other columns omitted for brevity...
)

BranchTbl_Mapper = mapper(BranchTbl, branches_table)
BranchTbl_Mapper.add_property('EnumsTbl', relation(EnumsTbl)) # 'enums'
table not shown
BranchTbl_Mapper.add_property(
    'Parent_BranchTbl',
    relation(
        BranchTbl,
        primaryjoin=branches_table.c.parent==branches_table.c.branchid,
        foreignkey=branches_table.c.branchid,
        uselist=False
    )
)


TEST CASE:
    session = create_session()
    query = session.query(BranchTbl_Mapper)
    object1 = query.get_by(branchid = 6)
    object2 = query.get_by(branchid = 3)
    print "original value of a property of a mapped-in object:",
object1.Parent_BranchTbl.branchid
    print "let's make the value this:", object2.branchid
    object1.Parent_BranchTbl = object2
    print "new value of a property of a mapped-in object:",
object1.Parent_BranchTbl.branchid

    session.save_or_update(object1)
    session.flush([object1])

OUTPUT:
   # first part output skipped.. it was way too long
original value of a property of a mapped-in object: 52
let's make the value this: 3
new value of a property of a mapped-in object: 3
[2006-10-25 11:43:56,029] [engine]: BEGIN
[2006-10-25 11:43:56,045] [engine]: COMMIT



Thanks much,
Rick


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to