public function testSetChanged() { $options = array(); $assoc = Mad_Model_Association_Base::factory('belongsTo', 'User', $options, new Article()); $assoc->setChanged(true); $this->assertTrue($assoc->isChanged()); $assoc->setChanged(false); $this->assertFalse($assoc->isChanged()); }
/** * Associations are lazy initialized as needed. This function is called when needed * to check if we need an association method */ protected function _initAssociations() { // only initialize if we haven't already if (!isset($this->_associationMethods) && isset($this->_associationList)) { // loop thru each define association foreach ($this->_associationList as $associationId => $info) { list($type, $options) = $info; $association = Mad_Model_Association_Base::factory($type, $associationId, $options, $this); $this->_associations[$associationId] = $association; // add list of dynamic methods this association adds foreach ($association->getMethods() as $methodName => $methodCall) { $this->_associationMethods[$methodName] = $association; } } } }
public function testGetMethods() { $assoc = Mad_Model_Association_Base::factory('hasMany', 'Tags', array('through' => 'Taggings'), new Article()); $expected = array('tags' => 'getObjects', 'tagIds' => 'getObjectIds', 'tagCount' => 'getObjectCount', 'addTag' => 'addObject', 'deleteTags' => 'deleteObjects', 'clearTags' => 'clearObjects', 'findTags' => 'findObjects'); $this->assertEquals($expected, $assoc->getMethods()); }
public function testGetMethods() { $assoc = Mad_Model_Association_Base::factory('belongsTo', 'User', array(), new Article()); $expected = array('user' => 'getObject', 'user='******'setObject', 'buildUser' => 'buildObject', 'createUser' => 'createObject'); $this->assertEquals($expected, $assoc->getMethods()); }
public function testGetMethods() { $assoc = Mad_Model_Association_Base::factory('hasAndBelongsToMany', 'Categories', array(), new Category()); $expected = array('categories' => 'getObjects', 'categories=' => 'setObjects', 'categoryIds' => 'getObjectIds', 'categoryIds=' => 'setObjectIds', 'categoryCount' => 'getObjectCount', 'addCategory' => 'addObject', 'replaceCategories' => 'replaceObjects', 'deleteCategories' => 'deleteObjects', 'clearCategories' => 'clearObjects', 'findCategories' => 'findObjects'); $this->assertEquals($expected, $assoc->getMethods()); }
public function testGetMethods() { $assoc = Mad_Model_Association_Base::factory('hasOne', 'Avatar', array(), new User()); $expected = array('avatar' => 'getObject', 'avatar=' => 'setObject', 'buildAvatar' => 'buildObject', 'createAvatar' => 'createObject'); $this->assertEquals($expected, $assoc->getMethods()); }
public function testGetMethods() { $assoc = Mad_Model_Association_Base::factory('hasMany', 'Articles', array(), new User()); $expected = array('articles' => 'getObjects', 'articles=' => 'setObjects', 'articleIds' => 'getObjectIds', 'articleIds=' => 'setObjectIds', 'articleCount' => 'getObjectCount', 'addArticle' => 'addObject', 'replaceArticles' => 'replaceObjects', 'deleteArticles' => 'deleteObjects', 'clearArticles' => 'clearObjects', 'findArticles' => 'findObjects', 'buildArticle' => 'buildObject', 'createArticle' => 'createObject'); $this->assertEquals($expected, $assoc->getMethods()); }