jpfuentes2 / php-activerecord

ActiveRecord implementation for PHP
http://www.phpactiverecord.org/
Other
1.32k stars 443 forks source link

build_* doesn't work as expected with a has_many relationship [patch] #69

Closed jcs closed 14 years ago

jcs commented 14 years ago
 class Thread extends ActiveRecord\Model {
      static $has_many = array(array("posts"));
 }

$thread->build_post() returns an error, because the association is "posts", but it is confusing to say build_posts() when it just returns one object.

a fix is to check the relationships hash for the pluralized version of the name before returning an error, allowing build_post() to work.

http://github.com/jcs/halfmoon/commit/3a158faefc0c5d81dae76c8b5cf16cbac9c93f73

kla commented 14 years ago

I moved the check to Model#__call instead since making the change in Table#get_relationship would affect everything else that uses it. For example all has_many relationships would then be accessible with a singular and plural name like: $thread->post and $thread->posts.

http://github.com/kla/php-activerecord/commit/ee47efa34d552094aa6e8adcbac503914c235f40