On Mar 26, 2012, at 11:13 AM, Torsten Irländer wrote:

> Hm... this approach does not seem to work:
> 
> AttributeError: 'ColumnProperty' object has no attribute 'mapper'
> 
> class_mapper(PersonItem).get_property('fkInstID') gives me the
> ColumnProperty which does not have any mapper:

try ".parent".





> 
> {'key': u'fkInstID', '_strategies': {<class
> 'sqlalchemy.orm.strategies.ColumnLoader'>:
> <sqlalchemy.orm.strategies.ColumnLoader object at 0x9cb804c>},
> 'group': None, '_is_polymorphic_discriminator': False, 'extension':
> None, 'deferred': False, 'doc': None, '_compile_finished': True,
> 'descriptor': None, '_compile_started': True, 'comparator_factory':
> <class 'sqlalchemy.orm.properties.Comparator'>, 'strategy_class':
> <class 'sqlalchemy.orm.strategies.ColumnLoader'>, 'instrument': True,
> '_creation_order': 166, 'parent': <Mapper at 0x98d794c; PersonItem>,
> 'strategy': <sqlalchemy.orm.strategies.ColumnLoader object at
> 0x9cb804c>, 'columns': [Column(u'fkInstID', INTEGER(display_width=10),
> ForeignKey(u'tbInstitutions.pkInstID'), table=<tbPersons>,
> server_default=DefaultClause(<sqlalchemy.sql.expression._TextClause
> object at 0x98d17cc>, for_update=False))], 'active_history': False}
> 
> Any further Ideas?
> 
> torsten
> 
> 
> 
> On 24 Mrz., 20:25, Torsten Irländer <torsten.irlaen...@googlemail.com>
> wrote:
>> Thank you Benjamin for your answer. I will test this after the
>> weekend.
>> 
>> Torsten
>> 
>> On 23 Mrz., 21:57, Benjamin Trofatter <bentrofat...@gmail.com> wrote:
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>>> I don't know if this is the canonical way of doing things, but you can
>>> accomplish what you're asking with the following:
>> 
>>> from sqlalchemy.orm import class_mapper
>> 
>>> parent_class = class_mapper(c2).get_property('parent').mapper.class_
>> 
>>> 2012/3/23 Torsten Irländer <torsten.irlaen...@googlemail.com>
>> 
>>>> Hi all,
>> 
>>>> Lets say i have two tables t1 and t2 which have a 1:n relationship and
>>>> are mapped to the classes c1 and c2.
>>>> c2.parent is an FK to PK c1.id. This is quite forward and works like a
>>>> charm.
>> 
>>>> What i want is to get information about relations to other classes
>>>> from within the mapped classes.
>>>> More precisely I'm interested in getting information about which class
>>>> is mapped in field c2.parent from with in the class c2. Ideally this
>>>> is not only the name of the class but the class itself.
>> 
>>>> Is this possible?
>>>> Any help on this is highly appreciated.
>> 
>>>> --
>>>> 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
>>>> sqlalchemy+unsubscr...@googlegroups.com.
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/sqlalchemy?hl=en.
> 
> -- 
> 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 
> sqlalchemy+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/sqlalchemy?hl=en.
> 

-- 
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to