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 have 2 models: Item and ItemPrice
Item hasMany ItemPrices
ItemPrice belongsTo Item
When I create new ItemPrice from Item update form (using relation controller), I need to access Item model (i.e parent model) when generation dropdown options in related model form.
Something like $this->item->...
But relation controller doesn't set relation to parent model before related model is added.
Last updated
I have deleted the solution posted earlier, because with this solution the new related model is not created...
Last updated
The only way to fix this problem that I found, is rather dirty solution.
Let's say, my parent model class is Item
. Then I can access it's id
directly from the post request:
$item = Item::find(post('Item.id'));
This code works only if you have id
field defined in fields.yaml
of parent model.
If not, you can create custom partial field and generate hidden input and "catch" it from post()
when related model's form is rendering to be displayed in popup.
Last updated
Very old topic, but strangely relevant for me now.
I added the following to the parent form controller in update.htm
<?= Form::open(['class' => 'layout','data-request-data'=>'quote_id:'.$formModel->getKey()]) ?>
and then in the child model where I needed it
$id = $this->exists ? $this->quote_id : post('quote_id');
2 years later I face the same issue! Has this issue been addressed in later versions of october?
1-5 of 5