Skip to content

Commit

Permalink
adding docs about crossdb habtm
Browse files Browse the repository at this point in the history
  • Loading branch information
rchavik committed Nov 28, 2011
1 parent 96e6ad9 commit 9c8671c
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
39 changes: 39 additions & 0 deletions en/models/associations-linking-models-together.rst
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,45 @@ like to fetch Recipe data when using the Ingredient model.

For more information on saving HABTM objects see :ref:`saving-habtm`

Cross database HABTM
~~~~~~~~~~~~~~~~~~~~

In some cases, you might want to store the join table in a separate database. To achieve
this, you need to create the join Model class with the appropriate ``$useDbConfig`` value
and specify it as the ``with`` key in the association configuration. For example, the
following configuration stores *Player* data in the default database, while models *Guild*
and *GuildsPlayer* are stored in a separated datasource called `guilddb`::

<?php
// Model/Player.php
class Player extends AppModel {
public $hasAndBelongsToMany = array(
'Guild' => array(
'className' => 'Guild',
'with' => 'PlayersGuild',
),
);
}

// Model/Guild.php
class Guild extends AppModel {
public $useDbConfig = 'guilddb';
public $hasAndBelongsToMany = array(
'Player' => array(
'className' => 'Guild',
'with' => 'PlayersGuild',
),
);
}

// Model/PlayersGuild.php
class PlayersGuild extends AppModel {
public $useDbConfig = 'guilddb';
}

.. note:: You need to ensure the database you are using supports cross database queries.

.. versionadded:: 2.1

.. _hasMany-through:

Expand Down
10 changes: 10 additions & 0 deletions en/models/model-attributes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,16 @@ Example usage::
public $name = 'Example';
}

schemaName
===========

This property holds the physical schema name in the database and
typically will be automatically set during model instantiation by
the model's datasource, see
:doc:`/models/datasources`.

.. versionadded:: 2.1

cacheQueries
============

Expand Down

0 comments on commit 9c8671c

Please sign in to comment.