Hi!
I have a model, let's call it Resource. And another, let's call it
Container. Each container can have any number of Resources, so they're
in many-to-many relationship. What's worse, they're in "association
object pattern" relationship because the association also carries the
amount of particular Resource associated with teh Container.
Now, when a Container is viewed I need to construct a (html) table
listing ALL resources available (simple select all from resources), but
ordered so that those resources that are in the container (amount > 0)
are at the top (ordered desc), followed by the resources that are not in
the container (implicitly amount = 0).
I figure I can do that the long way, selecting all the resources in a
sequence, then for each apply an implicit attribute of amount obtained
from another query, that of resources in this Container.
But I assume there's the "right way" using UNION, (union of resources in
the container with explicit amount, and all resources with implicit
amount=0), and I am not sure how to proceed.
class Container(Base):
__tablename__ = "containers"
container_id = ... # Integer
name = ...
resources = relationship("ResourcesInContainers")
class Resource(Base):
__tablename__ = ...
resource_id = .... # Integer
name ...
class ResourcesInContainers(Base):
__tablename__ = ...
resource_id = Column(Integer, ForeignKey("resources.resource_id"),
primary_key=True)
container_id = Column(Integer,
ForeignKey("containers.container_id", primary_key=True)
amount = Column(SmallInteger)
resource = relationship("Resource")
I need to query resources' id, name and amount.
Thanks!
--
.oO V Oo.
--
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
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.