In SQLAlchemy the "metadata" is the central object that binds tables
together and describes their relationships. It is not possible to describe
relationships between tables that are defined using different metadata
objects. As you know already, each Base creates its own shared metadata
object between all of its subclasses. If you really do want to share tables
between addons you either need to define that table per-metadata-object, or
share those particular objects via a common package.

If you'd like to also share the mapper relationships then you'll need to
share the Base subclasses (User, Product, etc). At that point you're
running out of reasons not to just have your database schema in a common
package that each of your addons depends on. You then have one
Base/metadata that is shared and one DBSession, so it is all very simple.
The only reason to have a separate metadata object is if you have an
unrelated schema you want to store either in the same database or elsewhere.

On Thu, Dec 15, 2011 at 7:02 PM, Viktor Nagy <viktor.n...@toolpart.hu>wrote:

> hi,
>
> I'm stuck and sweating with a "should be simple, so common" problem
> related sqlalchemy and portable pyramid app development.
>
> I would like bind together several apps using config.include.
> All these apps use their own DBSession and Base declarations. The
> DBSession shouldn't cause any troubles as scoped session is used
> everywhere, but this is not true about the Base declarations.
>
> If I don't want to import the Base of one of my apps (it's not feasible in
> my case anyway), then I have to move  every already defined table from
> other models' metadata to this Base.metadata, otherwise SQLAlchemy can not
> find related tables as they are contained within separate metadatas.
>
> Moreover, even when I come up with some really dirty solution and manage
> to run the pserve, the populate script needs a different approach just like
> writing tests, and it seems to me that in every situation I should invent
> new approaches, and I'm running out of ideas. :)
>
> I guess that overcoming such situations should be a common task, so I
> would be glad if you would share your experiences with me.
>
> thanks,
> Viktor
>
>
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "pylons-discuss" group.
> To post to this group, send email to pylons-discuss@googlegroups.com.
> To unsubscribe from this group, send email to
> pylons-discuss+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/pylons-discuss?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to pylons-discuss@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-discuss+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.

Reply via email to