Hello,
I have these classe where items (class Item) is related to channel object:
channel_items = Table(
"channel_items",
metadata,
Column("channel_id", Integer,
ForeignKey("channels.id")),
Column("item_id", Integer,
ForeignKey(Item.id))
)
class Channel(rdb.Model):
""" Set up channels table in the database """
rdb.metadata(metadata)
rdb.tablename("channels")
id = Column("id", Integer, primary_key=True)
title = Column("title", String(100))
items = relation(Item, secondary=channel_items, backref="channels")
class Item(rdb.Model):
""" Set up items table in the database """
rdb.metadata(metadata)
rdb.tablename("items")
id = Column("id", Integer, primary_key=True)
title = Column("title", String(100))
I know how to get all the columns using something like:
session = rdb.Session() channels = session.query(Channel).order_by(Channel.title)
However, I'd like to get some columns from both tables and the field items in channel object to be related to Item class because I've tried something like this:
session = rdb.Session()
channels = session.query(Channel.title, Item.title).order_by(Channel.title)
I got the channel title and item title, but I just get one item from every channel. I'd like to get all the items related to every channel.
Thanks in advance!