Hi,
maxi wrote:
> Hi,
>
> I´ve just using sqlalchemy 0.5.1 with python 2.6 and turbogers, but I
> found a little problem trying to configurate adjacency relationship
> with declarative base.
>
>
> My object class is something like this:
>
> class QueryGroup(DeclarativeBase):
> __tablename__ = 'queries_group'
>
> qry_grp_id = Column(Smallinteger, primary_key=True)
> qry_grp_desc = Column(Unicode(20), nullable=False)
> parent_id = relation('QueryGroup', backref='parent')
>
> When I try to generate my tables, I get an error like this:
>
> sqlalchemy.exc.ArgumentError: Could not determine join condition
> between parent/
> child tables on relation QueryGroup.parent_id. Specify a
> 'primaryjoin' expressi
> on. If this is a many-to-many relation, 'secondaryjoin' is needed as
> well.
>
> How can I specify the correct statement?
>
> Using traditional mapper approach, I can do:
>
> queries_group = Table(...)
>
> mapper(QueryGroup, queries_group, properties={
> 'children': relation(QueryGroup, cascade="all",
> backref=backref("parent", remote_side=
> [queries_group.c.qry_grp_id]))
> }
> )
>
>
> Can I do the same using declarative style? How?
>
I use declarative like this to do the above.
class Lang(Base):
__table__ = sa.Table(u'lang', metadata,
sa.Column(u'id', sa.Integer(), sa.Sequence('gen_lang_id'),
primary_key=True, nullable=False),
sa.Column(u'lang', sa.String(length=5, convert_unicode=False)),
)
class Users(Base):
__table__ = sa.Table(u'users', metadata,
sa.Column(u'id', sa.Integer(), sa.Sequence('gen_users_id'),
primary_key=True, nullable=False),
sa.Column(u'name', sa.String(length=20, convert_unicode=False)),
sa.Column(u'fk_lang', sa.Integer(), sa.ForeignKey(u'lang.id')),
)
lang = sao.relation(Lang)
could also be:
lang = sao.relation(Lang, backref='users')
Werner
> Thanks in advance.
> ---
> Maxi.
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> >
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---