Hi list,
For this problem I am even having trouble think of a proper subject for it.
I try my best to express as clear as possible and sorry for any confusions.
Say there are three classes with relationship defined as below:
class User(Base):
__tablename__ = 'users'
id = Column(Integer, Sequence('user_id_seq'), primary_key=True)
class Feedback(Base):
__tablename__ = 'feedbacks'
id = Column(Integer, Sequence('feedback_id_seq'), primary_key=True)
service_id = Column(Integer, ForeignKey('services.id'))
score=Column(Integer)
service=relationship('Service', backref=backref("feedbacks"))
class Service(Base):
__tablename__ = 'services'
id = Column(Integer, Sequence('service_id_seq'), primary_key=True)
provider_id = Column(Integer, ForeignKey('users.id'))
requester_id = Column(Integer, ForeignKey('users.id'))
provider = relationship('User', foreign_keys=provider_id, backref='
services_received')
requester = relationship('User', foreign_keys=requester_id, backref='
services_sent')
*User* and *Service* is a one to many relationship, and a user can be
a Service provider or requester.
For *Service* and *Feedback, *it is a one to many relationship too. A
requester can give a score to the Service.
*The question is, how can I get the sum(scores) of all services for a user?*
I thought I could do sth like:
#provider is a given object
*provider.services_recieved.feedbacks*
but it threw error:
*AttributeError: 'InstrumentedList' object has no attribute 'feedbacks'*
and I thought I also could :
*provider.services_recieved.query(Feedback)*
apparently it didn't have a query function.
I think by adding a user_id to the Feedback class will make this task
easier, however, that field is just a duplication for only this purpose.
Thanks.
--
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.