Help Referencing Relation Fields in Query
Closed this issue · 3 comments
Hello ikkez,
Thank you for this awesome plugin. I love FF3 and little enhancements like this make it even better.
Anyway, I was wondering if you could give me a little help. I have a sales table which contains an account ID (account column) and then an accounts table with the account info, so for the sales model I am using:
protected $fieldConf = [
'account' => [
'belongs-to-one' => 'Controllers\Account'
]
];
When looping the sales entries I can use @sale.account.name and this works fine.
<repeat group="{{@sales}}" value="{{@sale}}">
{{@sale.account.name}}
</repeat>
My question is how can I (or can I) reference the account.name field in the query if I want to search the accounts table?
$model_sales = new Sales();
$sales = $model_sales->find([
'account.name = ?', 'Bob'
],[
'order' => 'id DESC'
]);
So far this results in:
Column not found: 1054 Unknown column 'account.name' in 'where clause'
Hope that makes sense and thank you.
Using @name removes the sql error, but returns no results. I assume because it's just a variable, so same as entering a blank field name. It seems like I'm just missing something simple.
See the filter() and has() methods. There's also a part in the docs with examples. That should do what you're looking for.
See the filter() and has() methods. There's also a part in the docs with examples. That should do what you're looking for.
Great, thank you very much.