session.query(Employee).options(sa.orm.joinedload(Employee.jobs).load_only('id', 'first_name')).all()Thanks Simon,I've tried the following:session.query(Employee).options(sa.orm.joinedload(Employee.jobs).load_only('id', 'first_name')).all()which according to the documentation (http://docs.sqlalchemy.org/en/rel_0_9/orm/mapper_config.html#deferred-loading-with-multiple-entities) should work, but it throws an exception (ArgumentError: mapper option expects string key or list of attributes)Can you please provide an example?
--
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+...@googlegroups.com.
To post to this group, send email to sqlal...@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
Thanks Michael,
I'm using 0.9.7 and while your example did work, the following did not:
from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class Employee(Base):
__tablename__ = 'employee'
id = Column(Integer, primary_key=True)
first_name = Column(String)
_jobs = relationship("EmployeeJob", lazy="joined")
@property
def jobs(self):
return [item.job_id for item in sorted(self._jobs, key=attrgetter('id'))]
class EmployeeJob(Base):
__tablename__ = "employee_job"
job_id = Column(Integer, ForeignKey('job.id'))
class Job(Base):
__tablename__ = 'job'
id = Column(Integer, primary_key=True)
name = Column(String)
e = create_engine("sqlite://", echo=True)
Base.metadata.create_all(e)
session = Session(e)
session.query(Employee).options(joinedload(Employee.jobs).load_only('id', 'first_name')).all()
Notice that the difference here is that I'm using a property decorator on jobs, there is a link table (EmployeeJob), and I'm trying to load information of Employee (first_name should be from there)
Thanks,
Ofir
--
You received this message because you are subscribed to a topic in the Google Groups "sqlalchemy" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sqlalchemy/OprfrGJcoJU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sqlalchemy+...@googlegroups.com.
Thanks Michael,I'm using 0.9.7 and while your example did work, the following did not:
To unsubscribe from this topic, visithttps://groups.google.com/d/topic/sqlalchemy/OprfrGJcoJU/unsubscribe.
To post to this group, send email to sqlal...@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
Nevertheless, is there a way to achieve what I want? (which is to selectively load several columns and this 'jobs' property from Employee)
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sqlalchemy/OprfrGJcoJU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sqlalchemy+...@googlegroups.com.
Nevertheless, is there a way to achieve what I want? (which is to selectively load several columns and this 'jobs' property from Employee)
Thanks Jonathan,
I actually have more properties and relationships which were removed for the sake of the example.
You are right though, the performance gain was not as I hoped it would be.
I'll have to think of other methods (caching maybe)...
--