Due to how tables are remapped when using pluggables it's always better to
refer to Columns instead of tables for ForeignKeys, otherwise SQLA might
have issues automatically detecting join conditions.
A working example is in the form:
from tgext.pluggable import app_model, primary_key, LazyForeignKey
user_sample_table = Table('tg_user_sample', app_model.metadata,
Column('user_id', Integer, ForeignKey(app_model.User.user_id),
primary_key=True),
Column('sample_id', Integer, LazyForeignKey(lambda: Sample.uid),
primary_key=True)
)
class Sample(DeclarativeBase):
__tablename__ = 'plutest1_samples'
uid = Column(Integer, autoincrement=True, primary_key=True)
name = Column(Unicode(16))
user = relation(lambda: app_model.User, secondary=user_sample_table)
On Tue, Apr 16, 2013 at 5:24 PM, Luca Verardi <[email protected]>wrote:
> Hi I have yet another problem with tgext.pluggable.
>
> I Tried putting this model definition in my plugin
>
> tag_article= Table('tag_article', metadata,
> Column('tag_id', Integer, ForeignKey('tag.id'), primary_key=True),
> Column('article_id', Integer, ForeignKey('article.id'),
> primary_key=True))
>
> class Tag(DeclarativeBase):
> __tablename__ = 'tag'
>
> id = Column(Integer, autoincrement=True, primary_key=True)
> text= Column(Unicode(200))
>
> class Article(DeclarativeBase):
> __tablename__ = 'article'
>
> id = Column(Integer, autoincrement=True, primary_key=True)
> text= Column(Unicode(2000) )
>
> tags = relation(Tag, secondary=tag_article, backref='articles')
>
> but whenever I start TG:
> sqlalchemy.exc.ArgumentError: Could not determine join condition between
> parent/child tables on relationship Article.tags. Specify a 'primaryjoin'
> expression. If 'secondary' is present, 'secondaryjoin' is needed as well.
>
> I tried to move this model definition inside the main project and it works
> normally.
>
> --
> You received this message because you are subscribed to the Google Groups
> "TurboGears" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/turbogears?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
--
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/turbogears?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.