Trying to translate a hasOne field but getting an error: Call to a member function hasRelation() on array" on line 70 of /srv/www/dev2/modules/backend/traits/FormModelSaver.php
public function boot()
{
\RainLab\Blog\Models\Post::extend(function ($model) {
$model->translatable[] = 'blog[author]';
$model->hasOne['blog'] = ['Pkurg\Blog\Models\Blog'];
});
Event::listen('backend.form.extendFieldsBefore', function ($widget) {
if (!$widget->model instanceof \RainLab\Blog\Models\Post) {
return;
}
if (!$widget->model) {
return;
}
\Pkurg\Blog\Models\Blog::getFromPost($widget->model);
if ($widget->isNested === false) {
$widget->secondaryTabs['fields']['blog[author]'] =
[
'label' => 'Author',
'tab' => 'Extra',
];
}
});
}
screenshot-dev2 pkurg ru-2019 10 05-20_54_34
I think the way you define your hasOne relation is wrong. You are assigning an array instead of a class
Please show me the correct working example of translation hasOne field.
$model->hasOne['blog'] = 'Pkurg\Blog\Models\Blog';
You can use an array as well if you need to specify a key or table for the model
Ok. $model->hasOne['blog'] = 'Pkurg\Blog\Models\Blog';
We get the exact same error: Call to a member function hasRelation() on array" on line 70 of
/srv/www/dev2/modules/backend/traits/FormModelSaver.php
public function boot()
{
\RainLab\Blog\Models\Post::extend(function ($model) {
$model->translatable[] = 'blog[author]';
$model->hasOne['blog'] = 'Pkurg\Blog\Models\Blog';
});
Event::listen('backend.form.extendFieldsBefore', function ($widget) {
if (!$widget->model instanceof \RainLab\Blog\Models\Post) {
return;
}
if (!$widget->model) {
return;
}
\Pkurg\Blog\Models\Blog::getFromPost($widget->model);
if ($widget->isNested === false) {
$widget->secondaryTabs['fields']['blog[author]'] =
[
'label' => 'Author',
'tab' => 'Extra',
];
}
});
}
And in the last example, if removed $model->translatable[] = 'blog[author]';
Everything worked fine with $model->hasOne['blog'] = ['Pkurg\Blog\Models\Blog'];
but without translation.
I see, try making your blog model translatable instead
--
Marc
On Thu, Oct 10, 2019, 10:22 pkurg notifications@github.com wrote:
And in the last example, if removed $model->translatable[] =
'blog[author]';
Everything worked fine with $model->hasOne['blog'] =
['Pkurg\Blog\Models\Blog'];
but without translation.—
You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub
https://github.com/rainlab/translate-plugin/issues/517?email_source=notifications&email_token=AAPLTPTKRTOFZNHM7EXWGM3QN3Q5NA5CNFSM4I5YWRWKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEA3LWHA#issuecomment-540457756,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAPLTPS22TVZOXTCHXK7GJTQN3Q5NANCNFSM4I5YWRWA
.
useless support
I see, try making your blog model translatable instead
…
-- Marc
On Thu, Oct 10, 2019, 10:22 pkurg @.*> wrote: And in the last example, if removed $model->translatable[] = 'blog[author]'; Everything worked fine with $model->hasOne['blog'] = ['Pkurg\Blog\Models\Blog']; but without translation.
This will not work.
Why wouldn't it work?
Because before you write, I already tried all this.
Write a small test plugin and make sure.
@pkurg please be respectful. You are getting free support, and @mjauvin is trying to rule out various potential causes of your issue.
You are getting free support
So far I haven't received anything besides moral instruction.
That's all you'll get then.
@pkurg editing your comments to try to remove them is not mature behaviour. This is a free plugin, for a free project, and support is offered for free. I recommend that you take that into consideration before getting mad at the people freely giving you their own personal time to try to help you resolve your problems.
Most helpful comment
@pkurg please be respectful. You are getting free support, and @mjauvin is trying to rule out various potential causes of your issue.