On Feb 13, 2014, at 11:46 AM, Guido Winkelmann <gu...@ambient-entertainment.de> 
wrote:

> 
> 
> Am Donnerstag, 13. Februar 2014 15:46:31 UTC+1 schrieb Michael Bayer:
> 
> On Feb 13, 2014, at 6:23 AM, Guido Winkelmann 
> <gu...@ambient-entertainment.de> wrote: 
> 
> > Hi, 
> > 
> > Reading through the docs, I could not find out how to tell the cardinality 
> > of an object of type sqlalchemy.orm.properties.RelationshipProperty, i.e. 
> > whether it is one-to-many, many-to-one or many-to-many.  Mostly, I just 
> > need to know whether a relationship refers to just one object or a 
> > collection of objects. 
> > 
> > Can someone help me with that? 
> 
> So given a class: 
> 
> MyClass 
> 
> and a relationship at the class level: 
> 
> MyClass.some_relationship 
> 
> you get at the RelationshipProperty like this: 
> 
> MyClass.some_relationship.property 
> 
> That doesn't work for me.
> 
> For some reason, the relationship has the type 
> sqlalchemy.orm.dynamic.AppenderBaseQuery, which has no attribute "property".
> 
> Maybe that's because I'm using flask-sqlalchemy instead of just sqlalchemy 
> directly?

“MyClass” is a class, not an object:

from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()

class A(Base):
    __tablename__ = 'a'

    id = Column(Integer, primary_key=True)
    bs = relationship("B", lazy="dynamic")


class B(Base):
    __tablename__ = 'b'

    id = Column(Integer, primary_key=True)
    a_id = Column(Integer, ForeignKey('a.id'))

configure_mappers()

print A.bs.property





> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to sqlalchemy+unsubscr...@googlegroups.com.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/groups/opt_out.

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

Reply via email to