--- Ksenia Marasanova <kse...@gm...>
wrote:
> On Mon, 15 Nov 2004 05:11:48 -0800 (PST), Tomas
> Fulajtar
> <fu...@ya...> wrote:
> > Hi all,
> >
> > i would like to ask you if could be possible to
> acces
> > intermediate table column in many to many
> > relationship.
> >
> > For example:
> >
> > CREATE TABLE person (
> > id SERIAL,
> > username VARCHAR(100) NOT NULL UNIQUE
> > );
> >
> > CREATE TABLE role (
> > id SERIAL,
> > name VARCHAR(50) NOT NULL UNIQUE
> > );
> >
> > CREATE TABLE assigned_roles (
> > person INT NOT NULL,
> > role INT NOT NULL,
> > assigned_date DATE
> > );
> >
> > I would like to access the assigned_date column.
> Does
> > anybody have any idea? In the docs there is
> following
> > solution, but without using any columns from
> > intermediate table.
> >
> > class Person(SQLObject):
> > username = StringCol(length=100,
> alternateID=True)
> > roles = RelatedJoin('Role',
> joinColumn='person',
> > otherColumn='role',
> >
> > intermediateTable='assigned_roles')
> > class Role(SQLObject):
> > name = StringCol(length=50, alternateID=True)
> > roles = RelatedJoin('Person',
> joinColumn='role',
> > otherColumn='person',
> >
> > intermediateTable='assigned_roles')
>
> I think you can define class for assigned_roles,
> just like for any
> other SQLObject class:
>
> class AssignedRoles:
> person = ForeignKey('Person')
> role = ForeignKey('Role')
> assignedDate = DateTimeCol()
>
>
> --
> Ksenia
>
>
The problem here is that intermediate table has
usually no primary key - SQLObject self does not
create any primary key at creation table time.
Therefore you are not able to use this table as class.
That is the reason why it is not possible to use two
One- to many joins as i tried. Or I am wrong? I think
in general intermediate table SHOULD not have primary
key!
Tomas
__________________________________
Do you Yahoo!?
The all-new My Yahoo! - Get yours free!
http://my.yahoo.com
|