a tiny mvc framework for php using php-activerecord
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'master' of github.com:kla/php-activerecord

+41 -11
+6 -4
lib/php-activerecord/lib/Model.php
··· 1247 1247 $args = $args[0]; 1248 1248 1249 1249 $association_name = str_replace(array('build_', 'create_'), '', $method); 1250 + $method = str_replace($association_name, 'association', $method); 1251 + $table = static::table(); 1250 1252 1251 - if (($association = static::table()->get_relationship($association_name))) 1253 + if (($association = $table->get_relationship($association_name)) || 1254 + ($association = $table->get_relationship(($association_name = Utils::pluralize($association_name))))) 1252 1255 { 1253 - //access association to ensure that the relationship has been loaded 1254 - //so that we do not double-up on records if we append a newly created 1256 + // access association to ensure that the relationship has been loaded 1257 + // so that we do not double-up on records if we append a newly created 1255 1258 $this->$association_name; 1256 - $method = str_replace($association_name,'association', $method); 1257 1259 return $association->$method($this, $args); 1258 1260 } 1259 1261 }
+5 -5
lib/php-activerecord/lib/Relationship.php
··· 393 393 * 394 394 * <ul> 395 395 * <li><b>limit/offset:</b> limit the number of records</li> 396 - * <li><b>primary_key:</b> name of the primary_key of the association (defaults to "id")</li> 397 - * <li><b>group:</b> GROUP BY clause</li> 398 - * <li><b>order:</b> ORDER BY clause</li> 399 - * <li><b>through:</b> name of a model</li> 400 - * </ul> 396 + * <li><b>primary_key:</b> name of the primary_key of the association (defaults to "id")</li> 397 + * <li><b>group:</b> GROUP BY clause</li> 398 + * <li><b>order:</b> ORDER BY clause</li> 399 + * <li><b>through:</b> name of a model</li> 400 + * </ul> 401 401 * 402 402 * @var array 403 403 */
+12
lib/php-activerecord/lib/Serialization.php
··· 16 16 * <li><b>methods:</b> a string or array of methods to invoke. The method's name will be used as a key for the final attributes array 17 17 * along with the method's returned value</li> 18 18 * <li><b>include:</b> a string or array of associated models to include in the final serialized product.</li> 19 + * <li><b>only_method:</b> a method that's called and only the resulting array is serialized 19 20 * <li><b>skip_instruct:</b> set to true to skip the <?xml ...?> declaration.</li> 20 21 * </ul> 21 22 * ··· 106 107 $this->check_except(); 107 108 $this->check_methods(); 108 109 $this->check_include(); 110 + $this->check_only_method(); 109 111 } 110 112 111 113 private function check_only() ··· 139 141 if (method_exists($this->model, $method)) 140 142 $this->attributes[$method] = $this->model->$method(); 141 143 } 144 + } 145 + } 146 + 147 + private function check_only_method() 148 + { 149 + if (isset($this->options['only_method'])) 150 + { 151 + $method = $this->options['only_method']; 152 + if (method_exists($this->model, $method)) 153 + $this->attributes = $this->model->$method(); 142 154 } 143 155 } 144 156
+7
lib/php-activerecord/test/RelationshipTest.php
··· 191 191 $this->assert_equals($values, array_intersect_key($values, $venue->attributes())); 192 192 } 193 193 194 + public function test_has_many_build_association() 195 + { 196 + $author = Author::first(); 197 + $this->assert_equals($author->id, $author->build_books()->author_id); 198 + $this->assert_equals($author->id, $author->build_book()->author_id); 199 + } 200 + 194 201 public function test_belongs_to_create_association() 195 202 { 196 203 $event = $this->get_relationship();
+5
lib/php-activerecord/test/SerializationTest.php
··· 135 135 $this->assert_same(false,strpos(Book::find(1)->to_xml(array('skip_instruct' => true)),'<?xml version')); 136 136 $this->assert_same(0, strpos(Book::find(1)->to_xml(array('skip_instruct' => false)),'<?xml version')); 137 137 } 138 + 139 + public function test_only_method() 140 + { 141 + $this->assert_contains('<sharks>lasers</sharks>', Author::first()->to_xml(array('only_method' => 'return_something'))); 142 + } 138 143 }; 139 144 ?>
+6 -2
lib/php-activerecord/test/models/Author.php
··· 4 4 static $pk = 'author_id'; 5 5 // static $has_one = array(array('awesome_person', 'foreign_key' => 'author_id', 'primary_key' => 'author_id'), 6 6 // array('parent_author', 'class_name' => 'Author', 'foreign_key' => 'parent_author_id')); 7 - // static $has_many = array(array('books')); 7 + static $has_many = array('books'); 8 8 static $has_one = array( 9 9 array('awesome_person', 'foreign_key' => 'author_id', 'primary_key' => 'author_id'), 10 10 array('parent_author', 'class_name' => 'Author', 'foreign_key' => 'parent_author_id')); 11 - static $has_many; 12 11 static $belongs_to = array(); 13 12 static $setters = array('password'); 14 13 ··· 21 20 { 22 21 $value = strtoupper($value); 23 22 $this->assign_attribute('name',$value); 23 + } 24 + 25 + public function return_something() 26 + { 27 + return array("sharks" => "lasers"); 24 28 } 25 29 }; 26 30 ?>