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

lonnieje16829
lonnieje16829

I'm taking over development of a project a previously employee did based in October and run into something I have not been able to figure out.

We have a Company controller in our plugin. When editing that company in the backend, there's a tab with a relationship widget being rendered for that Comany's Locations. Right now, when you click "Add Locations" it lists all of the locations in the system, not just the ones belonging to that user. The relationships in the model appear to be setup correctly:

// In Company model:
public $hasMany = [
    'locations' => 'Vault\Octo\Models\Location'
];

// In Location model
public $belongsTo = [
    'company' => ['Vault\Octo\Models\Company'],
];

The partial view for that is simply calling the renderRelation:

<?= $this->relationRender('locations'); ?>

My question is how do I limit the locations returned to only those that belong to the company? Crawling through the forums today, I found the relationExtendViewWidget method that seems to be the right place to modify this, but changes made to the model don't stick, naturally.

public function relationExtendViewWidget(&$widget, $field)
{
    if ($field != 'locations')
    {
        return;
    }

    $widget->model->where('company_id', 1);
}

So where's the magic live that lets me modify this?

Thanks!

Sebastiaan Kloos (ICTBelang)
Sebastiaan Kloos (ICTBelang)

I had this problem too. You have to do where('company_id', '=', 1);

1-2 of 2

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