mitchellvanw / laravel-doctrine

NO LONGER MAINTAINED! A Doctrine 2 implementation that melts with Laravel
MIT License
187 stars 74 forks source link

support for multiple entity managers #122

Closed jaimesangcap closed 7 years ago

jaimesangcap commented 9 years ago

Is this feature already supported?

kirkbushell commented 9 years ago

It isn't, no - but why would you want multiple ones (out of curiosity).

boris-glumpler commented 9 years ago

For a multi tenant app where each tenant sits in their own database or schema for example. I'm working on an app right now, where most schemas are the same, but then there are a handful of tenants with completely unique tables. For those you need a separate entity manager each so you can migrate and seed them separately.

kirkbushell commented 9 years ago

That use-case makes me shiver for all sorts of reasons. lol

boris-glumpler commented 9 years ago

How so?

kirkbushell commented 9 years ago

Multi-tenant applications across multiple databases is imho a lot harder to manage than a single database that manages the requirements. It just makes me feel itchy :P

That's not to say it's not a good use-case for multiple entity managers - certainly it is.

boris-glumpler commented 9 years ago

It's harder, true. Why we switched from MySQL databases to PostgreSQL schemas. The concept is almost the same, but you still get the data separation while keeping things simple for database backups and cross-tenant queries.

kirkbushell commented 9 years ago

Yeah I guess you're trading one set of issues for another?

boris-glumpler commented 9 years ago

Not really. It works really well if you set your search_path accordingly to make sure that you always have your global schema in there right after the current tenant schema. Then your queries look first in the tenant schema and if it can't find the table there it looks in the global schema.

kirkbushell commented 9 years ago

If it's all in one schema you wouldn't have to do that, hence previous comment ;)

boris-glumpler commented 9 years ago

Yeah, but keeping all that data from different companies in the same schema makes me cringe. I wouldn't want that for mine.

kirkbushell commented 9 years ago

Just comes down to good code. Lots of companies do it :)

kirkbushell commented 9 years ago

Basecamp runs on a single database, to give you an idea. haha

boris-glumpler commented 9 years ago

Not a good enough reason :) Don't use Basecamp.

kirkbushell commented 9 years ago

hahaha. Well if I were to add to that - running a pretty complex SaaS application myself with the firm I work for - and opting for a single database has its architectural challenges, but it makes a number of things a lot simpler. In either case - we've digressed haha

jaimesangcap commented 9 years ago

I am practicing DDD and as it suggests, you need to divide your application by bounded context. Then each context should have different entity manager. I cant talk more about it since Im not an expert. Here is one example why we wanna use multiple entity managers https://msdn.microsoft.com/en-us/magazine/jj883952.aspx its a .Net implementation though.

kirkbushell commented 9 years ago

@Daskul that's not true at all. Bounded contexts do not necessarily mean a different connection or set of rules. Instead, they set boundaries by which other domains can access each other.

jaimesangcap commented 9 years ago

well then I dont have much argument. but how can you map 2 entities from different bounded context to the same database table?

FoxxMD commented 9 years ago

@Daskul and everyone else please use our new library, laravel-doctrine/orm. It has support for multiple entity managers and much, much more!

mitchellvanw commented 7 years ago

Closing because project is no longer maintained. Thanks.