On Apr 26, 2013, at 5:46 AM, Andi Blake <andi.ba...@googlemail.com> wrote:

> i'm still interested in the solution of 
> http://docs.sqlalchemy.org/en/rel_0_7/orm/session.html#simple-vertical-partitioning
>  since it toke me some time and i don't like having such an open issue ;) 
> this is my original scenario, having two ``DeclarativeBase``, one for the 
> ``site``, one for the ``market``. As you said, i changed the relationship to 
> ``user = sa.orm.relationship(User, foreign_keys=[User.id])`` which changes 
> the exception to::
> 
> sqlalchemy.exc.NoReferencedTableError: Foreign key associated with column 
> 'product_items.user_id' could not find table 'users' with which to generate a 
> foreign key to target column 'id'
> 
> this happens even though the schema is also assigned in the ``User`` class::
> 
> @timestampable()
> class User(DeclarativeBase):
> 
>     # necessary to create references from the market to this users
>     __table_args__ = {'schema': SITE_DATABASE_SCHEMA_NAME}
> 
>     id = sa.Column(sa.BigInteger,
>         Sequence('users_seq_id', optional=True),
>         primary_key=True)
> 
> 
> class ProductItem(Base):
>     user_id = sa.Column(
>         sa.BigInteger,
>         sa.ForeignKey('%s.%s.id' % (SITE_DATABASE_SCHEMA_NAME, 
> User.__tablename__)),
>         primary_key=True
>     )
>     user = sa.orm.relationship(User, foreign_keys=[User.id])
> 
> do you have a hint how to tell sqlalchemy to choose ``site.users`` rather 
> than ``users`` as table?

that should be correct, if User has "schema='site'" and ProductItem has 
"schema='market'", then a ForeignKey on ProductItem should refer to 
"site.user.id".  But similarly with the "User" issue, ForeignKey looks inside 
of the local MetaData collection to find the other table, and I see that User() 
has a different "Base" than ProductItem, which is the home base for a MetaData. 
  So you can alternatively specify the ForeignKey like 
"ForeignKey(User.__table__.c.id)" if you want to cross over two MetaData 
collections.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to