namespace Blog;
class Model_Post extends \Orm\Model {
protected static $_table_name = 'blog_post';
protected static $_has_many = array(
'comments' => array(
'key_from' => 'id',
'model_to' => 'Model_Comment',
'key_to' => 'post_id',
'cascade_save' => true,
'cascade_delete' => false,
)
);
}
Second Model: "Model_Comment"
namespace Blog;
class Model_Comment extends \Orm\Model {
protected static $_table_name = 'blog_post_comment';
protected static $_belongs_to = array(
'post' => array(
'key_from' => 'post_id',
'model_to' => 'Model_Post',
'key_to' => 'id',
'cascade_save' => true,
'cascade_delete' => false,
)
);
}
If I try to acces $post->comments in a view, I get the following error:
Fuel\Core\FuelException [ Error ]:
Related model not found by Has_Many relation "comments": Model_Comment
Both Models work, if use for instance:
$posts = Model_Post::find('all');
$comments = Model_Comment::find('all');
in a Controller.
What is the problem in the relation?
It looks like you're new here. If you want to get involved, click one of these buttons!