On Dec 8, 2007, at 2:09 PM, Brendan Arnold wrote:

>
> hmm strange, i tried this out with sqlalchemy version 0.4.1 but it
> does not seem to work...
>
>>>> s.name
> u'HALN01100601'
>>>> isinstance(s.name, sqlalchemy.orm.PropertyLoader)
> False
>>>> s.targets
> [<tcd_sample_database.model.samples.Target object at 0xb608dcac>]
>>>> isinstance(s.targets, sqlalchemy.orm.PropertyLoader)
> False
>
> both attributes were loaded by sqlalchemy. also,
>
>>>> getattr(s.materials, "direction")
> Traceback (most recent call last):
>  File "<console>", line 1, in ?
> AttributeError: 'InstrumentedList' object has no attribute 'direction'
>
>

here is a code example illustrating my previous email:

from sqlalchemy import *
from sqlalchemy.orm import *

from sqlalchemy.orm.properties import PropertyLoader
from sqlalchemy.orm.sync import ONETOMANY, MANYTOONE, MANYTOMANY

metadata = MetaData()

t = Table('foo', metadata, Column('id', Integer, primary_key=True))
t2 = Table('bar', metadata, Column('id', Integer, primary_key=True),  
Column('fooid', Integer, ForeignKey('foo.id')))

class T(object):pass
class T2(object):pass

mapper(T, t, properties={
     't2s':relation(T2)
})
mapper(T2, t2)

prop = T.t2s.property
if isinstance(prop, PropertyLoader):
     if prop.direction == ONETOMANY:
         print "onetomany"
    elif prop.direction == MANYTOONE:
        # etc


> brendan
>
>
>
>
> On Dec 3, 2007 9:30 PM, Michael Bayer <[EMAIL PROTECTED]>  
> wrote:
>>
>> id look at prop = MyClass.someattribute.property, use  
>> isinstance(prop,
>> PropertyLoader) to determine a relation and not a scalar, combined
>> with getattr(prop, "direction") == sqlalchemy.orm.sync.MANYTOMANY,
>> ONETOMANY, etc. to get the type of join.
>>
>>
>> On Dec 3, 2007, at 3:43 PM, Brendan Arnold wrote:
>>
>>>
>>> hi there,
>>>
>>> i'd like a way to determine if an attribute of an orm object is:
>>>
>>>   a:) a sqlalchemy generated list of objects (i.e. many-to-many)
>>>   b:) a single sqlalchemy joined object (i.e.one-to-many)
>>>   c:) a 'scalar' loaded from the database (i.e. a string, float,
>>> integer)
>>>
>>> at present i'm copying the text generated by
>>> 'type(orm_obj.joined_list)' to determine a: and a 'type(float, int
>>> etc.)' for c:, whats left is b.
>>>
>>> this seems shakey, is there a better way? are there some 'types'
>>> defined in sqlalchemy?
>>>
>>> brendan
>>>
>>>>
>>
>>
>>>
>>
>
> >


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