Hello all, First of all, I just want to say great work on this framwork... Loving every line of it.
I have two tables users and persons. Each has a primary key of id. After creating the crud models, I can access the tables and their values just fine. However I would like to define a one-to-one relationship between the two in order to access the value of one table through the field of another. (e.i. $user->person->full_name).
However when I try to define these relationships (one-to-one in User Table, belongs to in Persons Table) with the following code, I get a 'Trying to get property of non-object' error. Any help would be very appreciated. As I have spent quite a bit of time trying to find an answer.
<pre>
class Model_User extends \Model_Crud
{
// Set the table to use
protected static $_table_name = 'users';
protected static $_has_one = array(
'profile' => array(
'key_from' => 'id',
'model_to' => 'Model_Person',
'key_to' => 'person',
'cascade_save' => true,
'cascade_delete' => false,
)
);
}
class Model_Person extends \Model_Crud
{
// Set the table to use
protected static $_table_name = 'persons';
protected static $_belongs_to = array(
'post' => array(
'key_from' => 'user',
'model_to' => 'Model_User',
'key_to' => 'person',
'cascade_save' => true,
'cascade_delete' => false,
)
);
}
</pre>
Tables:
Users
-id
-username
-password
-person (id of person in persons table)
Persons
-id
-full_name
-age