Afeique Sheikh Mon Feb 13 15:18:21 -0500 2012

Subject: (SOLVED) Exception: 'Tag' must extend from ActiveRecord\Model' though it already does

Hi guys,

I have stumbled into a surprising issue. Trying to fetch posts (MySQL v5.1.49; PHP v5.3; PHP ActiveRecord v1.0) like so:

1 $posts = Post::find('all', array('order' => 'id desc'));

results in:

Fatal error: Uncaught exception 'ActiveRecord\RelationshipException' with message ''Tag' must extend from ActiveRecord\Model'

But class Tag definitely extends ActiveRecord\Model:

models/post.php

1 class Post extends ActiveRecord\Model {
2   static $has_many = array(
3       array('post_tag_relations', 'class_name' => 'Post_Tag_Relation'),
4       array('tags', 'through' => 'post_tag_relations')
5   );
6 }

models/tag.php

1 class Tag extends ActiveRecord\Model {
2   static $has_many = array(
3       array('post_tag_relations', 'class_name' => 'Post_Tag_Relation'),
4       array('posts', 'through' => 'post_tag_relations')
5   );
6 }

models/post_tag_relation.php

1 class Post_Tag_Relation extends ActiveRecord\Model {
2   static $belongs_to = array(
3       array('post'),
4       array('tag')
5   );
6 }

Changing the Post class to

1 class Post extends ActiveRecord\Model {
2   static $has_many = array(
3       array('post_tag_relations', 'class_name' => 'Post_Tag_Relation')
4   );
5 }

makes everything work out okay, but this isn't the sort of solution I'm looking for.

I feel like I'm messing up something simple, but no amount of digging has yet come to any avail. As ever, any input would be appreciated.


Afeique Sheikh Mon Feb 13 20:30:05 -0500 2012

I just found out I had another class named "tag" which I presume is what php activerecord was picking up on. This is what I get for making helper functions to instantiate classes instead of using the full name.

I'm going to go stab myself now, then keep programming.

(1-1/1)