Hello,
First of all, i love FuelPHP and am very happy about it. But while developing the backend of my new site I ran into some issues.
The base model I use for my blogging system looks basicly like this:
<code>
namespace Blog;
class Model_Blog extends \Orm\Model
{
protected static $_properties = array(
\\ Properties array.
);
protected static $_belongs_to = array(
'user' => array(
'model_to' => '\Model_User',
),
);
protected static $_has_many = array(
'comments' => array(
'model_to' => 'Comments\Model_Comment',
'key_to' => 'uri',
'key_from' => 'uri',
'cascade_delete' => true,
),
);
protected static $_has_one = array(
'category' => array(
'model_to' => '\Blog\Model_Category',
'key_to' => 'slug',
'key_from' => 'category',
),
);
}
</code>
The related models 'category' and 'comment' are set up with a belongs-to relation to the blog model and the correct 'key_to/from' parameters and the user model has many blogs...
Now if I try to delete a blog post I expected the ORM to delete its comments-children, too, because I set 'cascade_delete' to TRUE but instead I get the error:
<blockquote>
Call to a member function frozen() on a non-object
PKGPATH/orm/classes/hasone.php @ line 204
</blockquote>
and even if I remove the hasone-relation It outputs:
<blockquote>
Invalid argument supplied for foreach()
PKGPATH/orm/classes/hasmany.php @ line 235
</blockquote>
What am I doing wrong? Didn't I understand the relations correctly?
Thanks in advance for your replies.
You'll probably never have to use has_one. In that case most of the times the better way is to merge the tables to 1 table.
In this case you don't need a has_one relationship, but a belongs_to. The blog (post?) belongs to a category and a category has_many blogs. If that doesn't work, you can check the paths to the related models. You use:
Thanks for your reply.
I changed the relations, so the blog model belongs to category and the category has many blog posts and it solved the first error.
But the second one is still there, which sits in the hasmany relation...
<blockquote>
Invalid argument supplied for foreach()
PKGPATH/orm/classes/hasmany.php @ line 221
</blockquote>
and
<blockquote>
Invalid argument supplied for foreach()
PKGPATH/orm/classes/hasmany.php @ line 235
</blockquote>
the blog post gets deleted, but not the related comments... any ideas?
Thanks
edit: The different namespaces are set correctly. I splitted my site into modules, so each module has its own namespace.