Sorry, still a few mistakes in what I wrote (first testing what you
paste is a far better way to work) :
121 from sqlalchemy.orm import
deferred
122 from sqlalchemy import
Text
123
124 class
Base(DBBASE):
125 __tablename__ =
'base'
126 __mapper_args__ = {'polymorphic_identity': 'base',
'polymorphic_on':'type_'}
127 id = Column(Integer,
primary_key=True)
128 name =
Column(String(255))
129 description =
deferred(
130
Column(Text()),
131
group="full"
132
)
133 type_ = Column( String(30),
nullable=False)
134
135 class
Element(Base):
136 __tablename__ =
'element'
137 __mapper_args__ = {'polymorphic_identity':
'element'}
138 id = Column(ForeignKey("base.id"),
primary_key=True)
139 comments = deferred( Column(Text()), group="full", )
print(DbSession().query(Element).options(undefer_group('full')))
SELECT element.comments AS element_comments, element.id AS element_id,
base.id AS base_id, base.name AS base_name, base.type_ AS base_type_
FROM base INNER JOIN element ON base.id = element.id
Le 16/03/2015 17:33, tonthon a écrit :
> Sorry I was a bit too speed when writing that one :)
>
> So I've got a Base model :
> """
> class Base(DBBASE):
> __tablename__ =
> 'base'
> __mapper_args__ = {'polymorphic_identity': 'base', 'polymorphic_on':
> 'type_'}
> id = Column(Integer, primary_key=True)
> name = Column(String(255))
> description = deferred(
> Column(Text()),
> group="full"
> )
> type_ = Column( String(30), nullable=False)
> """
>
> and a child model
> """
> class Element(DBBASE):
> __tablename__ = 'element'
> __mapper_args__ = {'polymorphic_identity': 'element'}
> id = Column(ForeignKey("base.id"))
> comments = deferred( Column(Text()), group="full", )
> """
>
> The following query :
> """
> Element.query().options(undefer_group('full')).all()
> """
>
> doesn't load the description column, is that the expected behaviour ?
>
> Regards
>
>
> Le 16/03/2015 17:21, Michael Bayer a écrit :
>> tonthon <[email protected]> wrote:
>>
>>> Hi,
>>>
>>> I'm using polymorphism and I set up some deferred columns at each level
>>> of inheritance belonging to the same deferred group :
>>>
>>> """
>>> class Base(DBBASE):
>>> id = Column(Integer, primary_key=True)
>>> name = Column(String(255))
>>> description = deferred(
>>> Column(Text()),
>>> group="full"
>>> )
>>>
>>> class Element(DBBASE):
>>> id = Column(ForeignKey("base.id"))
>>> comments = deferred(
>>> Column(Text()),
>>> group="full",
>>> )
>>> """
>>>
>>> The following query :
>>>
>>> """
>>> Element.query().options(undefer_group('full')).all()
>>> """
>>>
>>> doesn't defer the description column, is that the expected behaviour ?
>> a query for Element here will not load objects of type “Base”, so I don’t
>> see where “description” comes into play.
>>
>> If you can provide a more complete example that would help.
>>
>>
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.