Dnia 2009-08-28, Pt o godzinie 10:51 -0400, Michael Bayer pisze: > Tefnet Developers wrote: > > > > Dnia 2009-08-27, czw o godzinie 10:51 -0400, Michael Bayer pisze: > > > >> you can also set up primaryjoin using the actual table > >> columns (i.e. PhysObject.locationId == Location.__table__.c.id). > >> > > > > Thanks, that worked really well :). Now i am stuck with something else > > in this subject: > > > > ===================================================================== > > # available at http://filip.math.uni.lodz.pl/column_pairs.py > > # Fails with Python-2.5.4 and SQLAlchemy-0.5.5 > > > > import sqlalchemy > > import sqlalchemy.ext.declarative > > > > ''' > > Fails with: > > > > File > > "/usr/lib/python2.5/site-packages/SQLAlchemy-0.5.4p2-py2.5.egg/sqlalchemy/orm/properties.py", > > line 836, in _determine_synchronize_pairs > > "marked as viewonly=True." % (self.primaryjoin, self) > > sqlalchemy.exc.ArgumentError: Could not locate any equated, locally > > mapped column pairs for primaryjoin condition '"PhysObject"."locationId" > > = "Location"."Id"' on relation PhysObject.location. For more relaxed > > rules on join conditions, the relation may be marked as viewonly=True. > > > > ''' > > > > I want to put definining .locationId and .location into one function, so > > I need to assing .locationId outside of the PhysObject class definition. > > > > Is using Mapper._configure_inheritance() a proper approach? > > > > > > no that is not something that should be done here at all, that's an > internal configuration function and if it "works" its something entirely > accidental. The way you're configuring seems a little awkward > (column_property and such) can you just try making it a little more > "normal" ? the join condition being received is not being parsed at all > for some reason.
Hi, thanks for quick reply... Awkward column_property is because of exception you'll get if try to set Column without column_proprerty around it: --- sqlalchemy.exc.ArgumentError: Column 'PhysObject.locationId' is not represented in mapper's table. Use the `column_property()` function to force this column to be mapped as a read-only attribute. --- which (I think) exposes a real problem (Column 'PhysObject.locationId' is not represented in mapper's table.). Thats why we try to execute Mapper._configure_inheritance() again, because mapped_table is not updated after adding new column/property to already compiled mapper Here is example of what I'm talking about: http://dpaste.com/hold/86736/ and inline version (just in case dpaste won't work) --- (Pdb) pprint(PhysObject.__mapper__.mapped_table.c.__dict__) {'_data': {u'PhysObject_Id': Column('Id', Integer(), ForeignKey('TefObject.Id'), table=<PhysObject>, primary_key=True, nullable=False), u'PhysObject_barCode': Column('barCode', String(length=12, convert_unicode=False, assert_unicode=None), table=<PhysObject>, nullable=False), u'TefObject_Id': Column('Id', Integer(), table=<TefObject>, primary_key=True, nullable=False), u'TefObject_objectType': Column('objectType', String(length=128, convert_unicode=False, assert_unicode=None), table=<TefObject>, nullable=False)}} (Pdb) pprint(PhysObject.__table__.c.__dict__) {'_data': {'Id': Column('Id', Integer(), ForeignKey('TefObject.Id'), table=<PhysObject>, primary_key=True, nullable=False), 'barCode': Column('barCode', String(length=12, convert_unicode=False, assert_unicode=None), table=<PhysObject>, nullable=False), 'locationId': Column('locationId', Integer(), ForeignKey('Location.Id'), table=<PhysObject>)}} (Pdb) PhysObject.__mapper__._configure_inheritance() (Pdb) pprint(PhysObject.__mapper__.mapped_table.c.__dict__) {'_data': {u'PhysObject_Id': Column('Id', Integer(), ForeignKey('TefObject.Id'), table=<PhysObject>, primary_key=True, nullable=False), u'PhysObject_barCode': Column('barCode', String(length=12, convert_unicode=False, assert_unicode=None), table=<PhysObject>, nullable=False), u'PhysObject_locationId': Column('locationId', Integer(), ForeignKey('Location.Id'), table=<PhysObject>), u'TefObject_Id': Column('Id', Integer(), table=<TefObject>, primary_key=True, nullable=False), u'TefObject_objectType': Column('objectType', String(length=128, convert_unicode=False, assert_unicode=None), table=<TefObject>, nullable=False)}} --- Is that a correct behavior (not updating mapped_table after adding new column to compiled mapper)? Tomasz Jezierski Tefnet --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
