I have 3 models. Company
, Deal
, Agent
An agent can belong to both a company and a deal. And a company has many deals.
I have 2 record finders on the deal form.
# deal/fields.yaml
company:
label: Company
type: recordfinder
agent:
label: Agent
type: recordfinder
dependsOn: company
I want to update the Deal Agent
field based on the selected Company’s Agent
I assume this should be done using dependsOn
and use the filterFields()
method on the Deal model. But for some reason, this doesn’t seem to be working for me.
// Deal.php
public function filterFields($fields, $context = null) {
// I'm getting the company here. So this is all good.
$company = Company::find($fields->company->value);
// But I'm struggling to actually set the agent on the deal.
// Neither of these work for me.
$fields->agent->value = $company->agent;
$fields->agent->value = $company->agent->id;
}
Am I missing something?