Hello everybody,

Is there a generic way to check if a primary key of an instance has
been set that works even if it has been set indirectly, via a
relation?

For example, I have tables and mappers:

category_translations_table = Table('category_translations', metadata,
        Column('category_id', types.Integer,
ForeignKey('categories.id'), primary_key=True),
        Column('lang_id', types.String(2), ForeignKey('languages.id'),
primary_key=True),
        Column('title', types.Unicode(100), nullable=False),
        Column('description', types.Unicode(255), nullable=True),
        Column('page_text', types.Text, nullable=True)
)

languages_table = Table('languages', metadata,
        Column('id', types.String(2), primary_key=True),
        Column('native_name', types.Unicode(30)),
        Column('english_name', types.Unicode(30))
)

mapper(CategoryTranslation, category_translations_table,  properties={
        'category': relation(Category),
        'language': relation(Language)
})

Then, I set a primary key indirectly:

translation = CategoryTranslation()
translation.category = session.query(Category).filter(....).one()
translation.language = session.query(Language).filter(....).one()

1. How to check whether the primary key is set? I cannot simply check
if every column of class_mapper(CategoryTranslation).primary_key is
set, because these field are empty until I save  save the object.

2. How to retrieve that key? I would like to check if the record
already exists.


Regards,
Adam




--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to