0

I want to separate my model in two databases because there is a part that's used by another databases as well. I'm wondering how to deal with:

  1. Joins among tables of both databases.
  2. If any other problems can show up.

Are there any other solutions that can solve this problem and it's better?

I'm going to use PostgreSQL with two databases and CakePHP.

balazs630
  • 3,421
  • 29
  • 46
Serginho
  • 7,291
  • 2
  • 27
  • 52

1 Answers1

0

In addition to models, have you looked at Config/database.php?

Models with joins and associations are supported.

Is this a read-only app, or will it be maintaining tables. If you are read-only, you can get running pretty quick by doing basic model stuff without worrying about joins and associations.

To leverage Cake's multi database capabilities, make sure you understand the model.php variable $useDbConfig and how it relates to Config/database.php

Often, within the model class in the model.php file where model is the name of the model for a given table,

public $useDbConfig = "PostgressOnAix";

Also, probably doesn't apply for you, but in Cakephp you can do this;

$this->loadModel("TableStoredTwoPlaces");
$this->TableStoredTwoPlaces->useDbConfig = "PostgresOnAix";

or even;

$modelName = "TableStoredTwoPlaces";
$this->loadModel($modelName);
$this->$modelName->useDbConfig = "PostgresOnAix";

The value of the model setting of useDbConfig maps to a variable defining and array in Config/database.php within the class DATABASE_CONFIG

Soup Cup
  • 101
  • 1
  • 5