public function testHasManyConfig() { $belongs_to1 = $this->parse(<<<EOF has_many: - authors: collection: auth EOF ); $fields_1 = Relation::sanitize('dummy_collection', key($belongs_to1), current($belongs_to1)); $this->assertTrue($fields_1 == array('authors' => array('collection' => 'auths', 'foreign_key' => 'dummy_collection_id', 'primary_key' => '_id'))); $belongs_to2 = $this->parse(<<<EOF has_many: - creator: collection: auth - authors: collection: auth EOF ); $fields_2 = Relation::sanitize('dummy_collection', key($belongs_to2), current($belongs_to2)); $this->assertTrue($fields_2 == array('creators' => array('collection' => 'auths', 'foreign_key' => 'dummy_collection_id', 'primary_key' => '_id'), 'authors' => array('collection' => 'auths', 'foreign_key' => 'dummy_collection_id', 'primary_key' => '_id'))); }
protected function sanitizeRelationships($collection_name, &$config) { if (!isset($config['relationships'])) { $config['relationships'] = array(); } // sanitize relationship definitions foreach ($config['relationships'] as $relation => $fields) { $config['relationships'][$relation] = Relation::sanitize($collection_name, $relation, $fields); } return $config; }