1

During last week I have been stuck with a scaling-related problem in cakephp 3.0.

Basically, I designed a application for e-commerce that will serve several clients. Each store will sell its products in a specific subdomain (client1.application.com; client2.application.com, etc). All the stores will share the same application source.

I want to have a common database for user authentication and other common resources, like tables for cities, countries, etc, so that all users can access all e-commerce stores that use this application with same login information.

Each client will have a database with its specific resources, e.g. tables with products, sales, etc.

I found this interesting article http://mark-story.com/posts/view/using-cakephp-and-a-horizontally-sharded-database and I already implemented that solution so that cakephp can know recognize the subdomain and select client’s database as the default connection. I changed all the models (users, etc.) that I want to use the common database so that they always connect to the common database. And it’s working.

However, I still have a problem when it comes to associations in cakephp. For example: each client has a table for administrators in their specific databases, that associates the Users table in the common_resources database so that when an administrator logs in, the application grants all the administration privileges for that subdomain.

To sum up, the issue concerns associations between tables in different databases. Thanks a lot!

Himani Trivedi
  • 158
  • 2
  • 3
  • 16
DUp
  • 11
  • 5
  • I would assume that this is only a problem for associations that are using joins (hasOne, belongsTo)? If so, maybe **http://stackoverflow.com/questions/32033558/cakephp-3-using-different-datascources-in-a-query/32034850** – ndm Aug 31 '15 at 15:58

1 Answers1

0

With well defined defaultConnectionName() in your Table classes you can define associations between entities stored in different databases with LazyLoad Plugin.

Restriction is that you are only able to load them lazily.

See also documentation

r34
  • 320
  • 2
  • 12