OmgDef / yii2-multilingual-behavior

Yii2 port of the yii-multilingual-behavior.
146 stars 60 forks source link

Virtual attribute creation #13

Closed armpogart closed 9 years ago

armpogart commented 9 years ago

Suppose I have 2 tables: Page

id
slug
active

and PageTranslation

id
page_id
language_id
title
content

If I use your behavior and use localized() query, it gives me error of unknown attribute. I've found out that I need to overload Model attributes() function and add title and content as virtual attributes for the behavior to work.

Why not create virtual attributes in behavior if they are not found, or maybe at least add this in documentation.

P.S. Thanks for this behavior for our beloved PHP framework.

OmgDef commented 9 years ago

@armpogart Did you override $languageField property in your query class? It should be language_id

armpogart commented 9 years ago

@OmgDef No, I haven't overridden $languageField, it is on it's default language, so it is commented out. And without overriding attributes() function Yii2 gives error that there is no such title attribute and same for content.

languageField field in database is also language, not language_id as in my example.

OmgDef commented 9 years ago

@armpogart What version of the extension do you use?

armpogart commented 9 years ago

We are using composer require: "omgdef/yii2-multilingual-behavior": "*" with "minimum-stability": "stable" It seems that latest release version was 1.0.3 and that was the reason I was getting that strange behaviour.

armpogart commented 9 years ago

It would be also great to mention behaviour version in files too, or at least at README, because having behaviour in vendor folder, it was impossible to tell what version I was using.

OmgDef commented 9 years ago

@armpogart You should modify require section in your composer.json to: "omgdef/yii2-multilingual-behavior": "~2.0" or "omgdef/yii2-multilingual-behavior": "~1.0" ,if you what to use the first version Docs for first version here https://github.com/OmgDef/yii2-multilingual-behavior/blob/f91d63403f02c8a3266796b41d197068d7ef7fbb/README.md