|
|
@@ -192,6 +192,13 @@ class Table implements RepositoryInterface, EventListenerInterface
|
|
|
protected $_entityClass;
|
|
|
|
|
|
/**
|
|
|
+ * Registry key used to create this table object
|
|
|
+ *
|
|
|
+ * @var string
|
|
|
+ */
|
|
|
+ protected $_repositoryAlias;
|
|
|
+
|
|
|
+ /**
|
|
|
* A list of validation objects indexed by name
|
|
|
*
|
|
|
* @var array
|
|
|
@@ -228,6 +235,9 @@ class Table implements RepositoryInterface, EventListenerInterface
|
|
|
*/
|
|
|
public function __construct(array $config = [])
|
|
|
{
|
|
|
+ if (!empty($config['repositoryAlias'])) {
|
|
|
+ $this->repositoryAlias($config['repositoryAlias']);
|
|
|
+ }
|
|
|
if (!empty($config['table'])) {
|
|
|
$this->table($config['table']);
|
|
|
}
|
|
|
@@ -349,6 +359,23 @@ class Table implements RepositoryInterface, EventListenerInterface
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * Returns the table registry key used to create this table instance
|
|
|
+ *
|
|
|
+ * @param string|null $repositoryAlias the key used to access this object
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
+ public function repositoryAlias($repositoryAlias = null)
|
|
|
+ {
|
|
|
+ if ($repositoryAlias !== null) {
|
|
|
+ $this->_repositoryAlias = $repositoryAlias;
|
|
|
+ }
|
|
|
+ if ($this->_repositoryAlias === null) {
|
|
|
+ $this->_repositoryAlias = Inflector::camelize($this->alias());
|
|
|
+ }
|
|
|
+ return $this->_repositoryAlias;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* Returns the connection instance or sets a new one
|
|
|
*
|
|
|
* @param \Cake\Database\Connection|null $conn The new connection instance
|
|
|
@@ -1379,7 +1406,7 @@ class Table implements RepositoryInterface, EventListenerInterface
|
|
|
$entity->clean();
|
|
|
$this->dispatchEvent('Model.afterSave', compact('entity', 'options'));
|
|
|
$entity->isNew(false);
|
|
|
- $entity->source($this->alias());
|
|
|
+ $entity->source($this->repositoryAlias());
|
|
|
$success = true;
|
|
|
}
|
|
|
}
|
|
|
@@ -1845,8 +1872,7 @@ class Table implements RepositoryInterface, EventListenerInterface
|
|
|
{
|
|
|
if ($data === null) {
|
|
|
$class = $this->entityClass();
|
|
|
- $entity = new $class;
|
|
|
- $entity->source($this->alias());
|
|
|
+ $entity = new $class(['source' => $this->repositoryAlias()]);
|
|
|
return $entity;
|
|
|
}
|
|
|
if (!isset($options['associated'])) {
|
|
|
@@ -2007,7 +2033,11 @@ class Table implements RepositoryInterface, EventListenerInterface
|
|
|
}
|
|
|
$entity = new Entity(
|
|
|
$options['data'],
|
|
|
- ['useSetters' => false, 'markNew' => $options['newRecord']]
|
|
|
+ [
|
|
|
+ 'useSetters' => false,
|
|
|
+ 'markNew' => $options['newRecord'],
|
|
|
+ 'source' => $this->repositoryAlias()
|
|
|
+ ]
|
|
|
);
|
|
|
$fields = array_merge(
|
|
|
[$options['field']],
|