2 messages in com.googlegroups.sqlalchemy[sqlalchemy] How do I 'relation' this?
FromSent OnAttachments
Pedro Algarvio, aka, s0undt3ch26 Aug 2007 14:59 
Pedro Algarvio, aka, s0undt3ch26 Aug 2007 17:22 
Subject:[sqlalchemy] How do I 'relation' this?
From:Pedro Algarvio, aka, s0undt3ch (uf@ufsoft.org)
Date:08/26/2007 02:59:13 PM
List:com.googlegroups.sqlalchemy

Firstly, I'll explain my database layout:

I have a User table, which it's layout is not that important to the problem at
hands; A Bots Table: bots = sqla.Table('bots', metadata, sqla.Column('id', sqla.Integer, primary_key=True, autoincrement=True), sqla.Column('nick', sqla.Unicode, nullable=False, unique=True), sqla.Column('name', sqla.Unicode, nullable=True, unique=False), sqla.Column('passwd', sqla.Unicode, nullable=True, unique=False), sqla.Column('user_id', sqla.Integer, sqla.ForeignKey('users.id')), )

Each user is allowed to have several bots.

A networks Table: networks = sqla.Table('networks', metadata, sqla.Column('id', sqla.Integer, primary_key=True, autoincrement=True), sqla.Column('name', sqla.Unicode, nullable=False, unique=False), sqla.Column('address', sqla.Unicode, nullable=False, unique=False), sqla.Column('address', sqla.Unicode, nullable=False, unique=False), sqla.Column('port', sqla.Integer, nullable=False, unique=False), ) sqla.Index('networks_idx', networks.c.address, networks.c.port, unique=True)

networkbots_association = sqla.Table('networkbots_association', metadata, sqla.Column('id', sqla.Integer, primary_key=True, autoincrement=True), sqla.Column('network_id', sqla.Integer, sqla.ForeignKey('networks.id')), sqla.Column('bot_id', sqla.Integer, sqla.ForeignKey('bots.id')) ) sqla.Index('networkbots_association_idx', networkbots_association.c.network_id, networkbots_association.c.bot_id, unique=True)

Each bot is allowed to have a list of networks; I do that by an association table because 2 bots might share the same network.

Then, here's where my problem starts, I have a channels table. The same channel name might appear in 2 different networks, when such happens
there should be 2 channels, one for each of the networks.

Apart from that, I can't have a networks.id foreign key for channels, then 2
bots sharing the same network would have the same channels.

So, the foreign keys to use on channels should be networkbots_association.id?

Any help would be wonderfull. Regards,