This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
I've done some searching and have not found an answer to my problem...
I am extending the Users plugin to include another type of "group." Specifically, I want to use the RainLab Blog Categories Model in my new plugin. I want to populate the relation widget with the categories. I am able to add the relation widget to my new plugin, but when I try to save the user, I this error:
"Trying to get property of non-object" and it mentions my hasOne relationship.
Here is my code:
public function boot()
{
UserModel::extend(function($model)
{
$model->hasOne['category'] = [
'RainLab\Blog\Models\Category',
'key' => 'category'
//'table' => 'rainlab_blog_categories',
//'key' => 'category',
];
});
}
Just a quick update.. I think I have the problem solved although I'm not sure why this works.
I changed the model reference from 'category' to 'jobCategory' and made it a belongsTo. Here is the updated code:
public function boot()
{
UserModel::extend(function($model)
{
$model->belongsTo['jobCategory'] = [
'RainLab\Blog\Models\Category',
'key' => 'category'
//'table' => 'rainlab_blog_categories',
//'key' => 'category',
];
});
CategoryModel::extend(function($model)
{
$model->hasMany['users'] = [
'RainLab\User\Models\User',
];
});
}
Last updated
Now I have some questions about my relation form field definition. Here is the code:
UsersController::extendFormFields(function($form, $model, $context) { if (!$model instanceof UserModel) { return; } $form->addTabFields([ 'jobCategory' => [ 'label' => 'wwrf.profile::lang.profile.category', 'tab' => 'wwrf.profile::lang.profile.tab', 'type' => 'relation', 'select' => 'name', 'nameFrom' => 'name', 'descriptionFrom' => 'name', 'span' => 'right' ] ]); }
The relation widget pulls all the categories from the blog plugin. I would like to display only certain categories, for example, those with a particular parent_id. I tried changing my select option to:
'select' => with('parent_id', 3),
However, this displays only a '3' in the drop down, instead of the category name. I have also tried using a where statement and that does not seem to work.
Any advice appreciated. Thanks in advance.
Last updated
1-3 of 3