/** * Test keys() * * @return void */ public function testKeys() { $belongsTo = new BelongsTo(''); $this->associations->add('Users', $belongsTo); $this->associations->add('Categories', $belongsTo); $this->assertEquals(['users', 'categories'], $this->associations->keys()); $this->associations->remove('Categories'); $this->assertEquals(['users'], $this->associations->keys()); }
/** * Returns an array that can be used to describe the internal state of this * object. * * @return array */ public function __debugInfo() { $conn = $this->connection(); return ['registryAlias' => $this->registryAlias(), 'table' => $this->table(), 'alias' => $this->alias(), 'entityClass' => $this->entityClass(), 'associations' => $this->_associations->keys(), 'behaviors' => $this->_behaviors->loaded(), 'defaultConnection' => $this->defaultConnectionName(), 'connectionName' => $conn ? $conn->configName() : null]; }
/** * {@inheritDoc} * * Those entries in `$entities` that cannot be matched to any record in * `$data` will be discarded. Records in `$data` that could not be matched will * be marshalled as a new entity. * * When merging HasMany or BelongsToMany associations, all the entities in the * `$data` array will appear, those that can be matched by primary key will get * the data merged, but those that cannot, will be discarded. * * You can limit fields that will be present in the merged entities by * passing the `fieldList` option, which is also accepted for associations: * * ``` * $articles = $this->Articles->patchEntities($articles, $this->request->data(), [ * 'fieldList' => ['title', 'body'], * 'associated' => ['Tags', 'Comments.Users' => ['fieldList' => 'username']] * ] * ); * ``` * * You can use the `Model.beforeMarshal` event to modify request data * before it is converted into entities. */ public function patchEntities($entities, array $data, array $options = []) { if (!isset($options['associated'])) { $options['associated'] = $this->_associations->keys(); } $marshaller = $this->marshaller(); return $marshaller->mergeMany($entities, $data, $options); }