views:

36

answers:

0

Hello,

I have these classes:

class Channel(rdb.Model):
    rdb.metadata(metadata)
    rdb.tablename("channels")

    id = Column("id", Integer, primary_key=True)
    title = Column("title", String(100))


    items = relationship("MediaItem", secondary=channel_items, order_by="MediaItem.titleView", backref="channels")

class MediaItem(rdb.Model):
    rdb.metadata(metadata)
    rdb.tablename("media_items")

    id = Column("id", Integer, primary_key=True)
    title = Column("title", String(100))

class User(rdb.Model):
    rdb.metadata(metadata)
    rdb.tablename("users")

    id = Column("id", Integer, primary_key=True)
    name = Column("name", String(50))

    channels = relationship("Channel", secondary=user_channels, order_by="Channel.titleView", backref="users")

MediaItem is related to Channel and Channel is related to User.

if I'd like to select some columns from items and channels, I'd do this:

session = Session()
result = session.query(Channel).join(Channel.items).values(Channel.title, Item.title)

I get an instance of Channel class with its items.

My problem is I don't know how to select some columns from User, Channel and Item. How can I make a query where for example, I can select the User.name property and its channels with only Channel.title property and the items of those channels with only Item.title property?

Thanks in advance!