ORM belongs_to not loading relation
Closed this issue · 2 comments
happyDemon commented
In the model I'm trying to load the relation 'type' I have this:
use Formo_ORM;
protected $_belongs_to = array(
'type' => array(
'model' => 'Item_Type',
'foreign_key' => 'type_id',
'formo' => TRUE
),
);
...
in the model Item_Type I have this:
use Formo_ORM;
protected $_primary_val = 'name';
public function candidate_key()
{
if (!$this->loaded()) return FALSE;
return $this->name;
}
...
According to the docs this should load the relation I think? I was expecting a select input with relation records as options, but I simply got a text input field.
Is there something I'm doing wrong or is this a bug?
bmidget commented
Yup, you're right, it should load.
bmidget commented
I just confirmed that the auto-loading belongs_to foreign keys works.
Here's an example:
In the User model, it belongs_to 'class'
protected $_belongs_to = [
'class' => [
'model' => 'Class',
'foreign_key' => 'class_id',
'formo' => true,
]
];
Then when you get the form, the class_id
field will be the relationship.
$form = $user->get_form(['class_id']);