Hi. Thanks yor suggestions but it does not work for me. I'm guessing
i'm doing something wrong.
I've got this two classes (User , Groups) in seperet files, where i've
got to put the relation (relationship)? in both files? or just the one
with the ForeignKey?
Also, is the relationship must be placed inside the class?

On 24 Sie, 16:20, werner <wbru...@free.fr> wrote:
>   On 24/08/2010 15:53, werner wrote:
>
>
>
> >  Hi,
>
> > On 24/08/2010 10:14, Dobrysmak wrote:
> >> Hi guys.
>
> >> I've got a little problem with the sqlalchemy syntax.
> >> I've got two tables with relations:
>
> >> Table_Goups
> >> id int(4) PrimaryKey not null,
> >> name varchar(50) not null;
>
> >> and
>
> >> Table_User
> >> id int(4) Primary Key not null,
> >> login varchar(50) not null,
> >> id_group int(4) Foreign Key not null;
>
> >> i would like to build a query that would gets the user data from
> >> Table_User and the id_group but insted od showing the id_group number
> >> i want to show the Table_Groups.name
>
> >> Can anyone help?
>
> > I use SA declarative, so you would define something like this in your
> > model:
>
> > class Group(Base):
> >     __table__ = sa.Table(u'groups', metadata,
> >     sa.Column(u'id', sa.Integer(), sa.Sequence('gen_contact_id'),
> > primary_key=True, nullable=False),
> >     sa.Column(u'name', sa.String(length=70, convert_unicode=False),
> > nullable=False),
> >     )
>
> Oops, a copy/paste error, should be: sa.Sequence('gen_group_id')
>
> > class User(Base):
> >     __table__ = sa.Table(u'users', metadata,
> >     sa.Column(u'id', sa.Integer(), sa.Sequence('gen_contact_id'),
> > primary_key=True, nullable=False),
>
> and another one, a copy/paste error, should be: sa.Sequence('gen_user_id')
>
>
>
> >     sa.Column(u'name', sa.String(length=70, convert_unicode=False),
> > nullable=False),
> >     sa.Column(u'fk_group', sa.Integer(), sa.ForeignKey(u'groups.id'),
> > nullable=False),
> >     )
>
> >     group = sao.relation('Group', backref='user')
>
> > And then to query you could do e.g. this:
>
> > for usr in session.query(db.User).all():
> >     print 'user: %s, group name: %s' % (usr.name, usr.group.name)
>
> > Check out the SA doc, especially the tutorials:
> >http://www.sqlalchemy.org/docs/ormtutorial.html
> >http://www.sqlalchemy.org/docs/ormtutorial.html#creating-table-class-...
>
> > Hope this helps
> > Werner

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@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.

Reply via email to