···12471247 $args = $args[0];
1248124812491249 $association_name = str_replace(array('build_', 'create_'), '', $method);
12501250+ $method = str_replace($association_name, 'association', $method);
12511251+ $table = static::table();
1250125212511251- if (($association = static::table()->get_relationship($association_name)))
12531253+ if (($association = $table->get_relationship($association_name)) ||
12541254+ ($association = $table->get_relationship(($association_name = Utils::pluralize($association_name)))))
12521255 {
12531253- //access association to ensure that the relationship has been loaded
12541254- //so that we do not double-up on records if we append a newly created
12561256+ // access association to ensure that the relationship has been loaded
12571257+ // so that we do not double-up on records if we append a newly created
12551258 $this->$association_name;
12561256- $method = str_replace($association_name,'association', $method);
12571259 return $association->$method($this, $args);
12581260 }
12591261 }
+5-5
lib/php-activerecord/lib/Relationship.php
···393393 *
394394 * <ul>
395395 * <li><b>limit/offset:</b> limit the number of records</li>
396396- * <li><b>primary_key:</b> name of the primary_key of the association (defaults to "id")</li>
397397- * <li><b>group:</b> GROUP BY clause</li>
398398- * <li><b>order:</b> ORDER BY clause</li>
399399- * <li><b>through:</b> name of a model</li>
400400- * </ul>
396396+ * <li><b>primary_key:</b> name of the primary_key of the association (defaults to "id")</li>
397397+ * <li><b>group:</b> GROUP BY clause</li>
398398+ * <li><b>order:</b> ORDER BY clause</li>
399399+ * <li><b>through:</b> name of a model</li>
400400+ * </ul>
401401 *
402402 * @var array
403403 */
+12
lib/php-activerecord/lib/Serialization.php
···1616 * <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
1717 * along with the method's returned value</li>
1818 * <li><b>include:</b> a string or array of associated models to include in the final serialized product.</li>
1919+ * <li><b>only_method:</b> a method that's called and only the resulting array is serialized
1920 * <li><b>skip_instruct:</b> set to true to skip the <?xml ...?> declaration.</li>
2021 * </ul>
2122 *
···106107 $this->check_except();
107108 $this->check_methods();
108109 $this->check_include();
110110+ $this->check_only_method();
109111 }
110112111113 private function check_only()
···139141 if (method_exists($this->model, $method))
140142 $this->attributes[$method] = $this->model->$method();
141143 }
144144+ }
145145+ }
146146+147147+ private function check_only_method()
148148+ {
149149+ if (isset($this->options['only_method']))
150150+ {
151151+ $method = $this->options['only_method'];
152152+ if (method_exists($this->model, $method))
153153+ $this->attributes = $this->model->$method();
142154 }
143155 }
144156
+7
lib/php-activerecord/test/RelationshipTest.php
···191191 $this->assert_equals($values, array_intersect_key($values, $venue->attributes()));
192192 }
193193194194+ public function test_has_many_build_association()
195195+ {
196196+ $author = Author::first();
197197+ $this->assert_equals($author->id, $author->build_books()->author_id);
198198+ $this->assert_equals($author->id, $author->build_book()->author_id);
199199+ }
200200+194201 public function test_belongs_to_create_association()
195202 {
196203 $event = $this->get_relationship();