This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

KurtJensen
KurtJensen

I created a model "PTOParent" that extends RainLab.User and now when I try save that model from backend controller I get error involving ShahiemSeymor.Roles

<?php namespace KurtJensen\PTO\Models;

use RainLab\User\Models\User;

/**
 * parent Model
 */
class Volunteer extends User {
    /**
     * @var string The database table used by the model.
     */
    //protected $table = 'users';

    /**
     * @var array Relations
     */
    public $hasMany = [
        'students' => ['KurtJensen\PTO\Models\Student',
            'key' => 'user_id',
            'otherKey' => 'id'],
    ];

    public $belongsTo = [
        'school' => ['KurtJensen\PTO\Models\School',
            'key' => 'school_id',
            'otherKey' => 'id'],
    ];

    public $belongsToMany = [
        'groups' => ['ShahiemSeymor\Roles\Models\Group',
            'table' => 'shahiemseymor_assigned_roles',
            'otherKey' => 'id',
            'key' => 'user_id'],

        'permissions' => ['ShahiemSeymor\Roles\Models\Group',
            'table' => 'shahiemseymor_assigned_roles',
            'otherKey' => 'id',
            'key' => 'user_id'],
    ];
...

I am trying to figure out where/when ShahiemSeymor\Roles is getting triggered? The error I get is :

"SQLSTATE[42S22]: Column not found: 1054 Unknown column 'shahiemseymor_assigned_roles.volunteer_id' in 'field list' (SQL: select `shahiemseymor_roles`.*, `shahiemseymor_assigned_roles`.`volunteer_id` as `pivot_volunteer_id`, `shahiemseymor_assigned_roles`.`role_id` as `pivot_role_id` from `shahiemseymor_roles` inner join `shahiemseymor_assigned_roles` on `shahiemseymor_roles`.`id` = `shahiemseymor_assigned_roles`.`role_id` where `shahiemseymor_assigned_roles`.`volunteer_id` = 7)" on line 624 of /home/kurt/www/PTOVol/vendor/laravel/framework/src/Illuminate/Database/Connection.php"

BTW my back-end form does not include roles:

fields:

    name:
        label: rainlab.user::lang.user.name
        span: auto

    surname:
        label: rainlab.user::lang.user.surname
        span: auto

    school_id:
        label: School
        type: dropdown
        span: left

tabs:
    fields:
        students:
            tab: students
            type: partial
            path: $/kurtjensen/pto/models/student/sub_form.htm

        email:
            label: rainlab.user::lang.user.email
            tab: rainlab.user::lang.user.account
            span: full

        password:
            label: rainlab.user::lang.user.reset_password
            comment: rainlab.user::lang.user.reset_password_comment
            tab: rainlab.user::lang.user.account
            type: password
            span: left

        password_confirmation:
            label: rainlab.user::lang.user.confirm_password
            comment: rainlab.user::lang.user.confirm_password_comment
            tab: rainlab.user::lang.user.account
            type: password
            span: right

I understand where Roles extends users here: https://github.com/Shahiem/frontend-roles-manager/blob/master/Plugin.php#L32 , but I don't understand why back-end is querying roles if I don't even have those fields in my form.

Last updated

KurtJensen
KurtJensen

Controller:

<?php namespace KurtJensen\PTO\Controllers;

use BackendMenu;
use Backend\Classes\Controller;

/**
 * Parents Back-end Controller
 */
class Volunteers extends Controller {
    public $implement = [
        'Backend.Behaviors.FormController',
        'Backend.Behaviors.ListController',
        'Backend.Behaviors.RelationController',
    ];

    public $formConfig = 'config_form.yaml';
    public $listConfig = 'config_list.yaml';
    public $relationConfig = 'config_relation.yaml';

    public function __construct() {
        parent::__construct();

        BackendMenu::setContext('KurtJensen.PTO', 'pto', 'volunteers');
    }
}

# ===================================
#  Relation Behavior Config
# ===================================

students:
    label: Students
    list: ~/plugins/kurtjensen/pto/models/student/_Volunteer_rel_columns.yaml
    form: ~/plugins/kurtjensen/pto/models/student/_Volunteer_rel_fields.yaml
    manage:
        recordsPerPage: 10
        showSearch: true
    view:
        toolbarButtons: create|delete
        showSearch: true

    # ===================================
#  Form Behavior Config
# ===================================

# Record name
name: Volunteer

# Model Form Field configuration
form: $/kurtjensen/pto/models/volunteer/fields.yaml

# Model Class name
modelClass: KurtJensen\PTO\Models\Volunteer
# modelClass: RainLab\User\Models\User

# Default redirect location
defaultRedirect: kurtjensen/pto/volunteers

# Create page
create:
    title: Create Volunteer
    redirect: kurtjensen/pto/volunteers/update/:id
    redirectClose: kurtjensen/pto/volunteers

# Update page
update:
    title: Edit Volunteer
    redirect: kurtjensen/pto/volunteers
    redirectClose: kurtjensen/pto/volunteers

# Preview page
preview:
    title: Preview Volunteer
KurtJensen
KurtJensen

Thanks to some help from jwilson8767_ in the IRC channel for helping me solve this issue.

His suggestion to add :

/**
 * Get the default foreign key name for the model.
 *
 * @return string
 */
public function getForeignKey()
{
    return 'user_id';
}

to the the Volunteer.php model file solved the issue.

1-3 of 3

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.