-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Where to put model rules()? #9
Comments
I do change the default rules very often. So I agree it should be in the extended model. |
In the extended model seems to make sense, but why not an option? |
Extended Model is the best place |
After I think about it, what if it's best that i generate on both model and the extended model merge parent rules with extended rules.. so if DB structure is changed, you don't have to type manually the validation of the new column.. what do you guys think? |
For me, the difference between model and extended model is complicating the code. Every time I have to ask myself where to put and find things. Give an option to generate just one model with all code in it. Gone are the questions! |
you should not type anything on the base model actually.. base models are for generated by gii only. so u don't have to move any code if you want to re-structure your tables. on yii 1(i built the related CRUD generator too), i experienced that if i want to restructure the table, I have to backup my functions on the models before i re-generated the models |
Well, sometime I have add new complex relations. If I put them in the extended model, I have two places with relations. Mmmm... |
—Reply to this email directly or view it on GitHub. |
Not complex, but nevertheless. A function to return the name of an id with the id attached. The same function I use everywhere for the select2 pulldown.
|
Well, basically u dont type anything on the base models.. so that function On Mon, Feb 15, 2016, 16:15 Arjen Meijer notifications@github.com wrote:
|
Yes, but than I have two places to store getFunctions. What (logically) differentiates the gii generated ones from the hand coded ones? I my head it are just getFunctions which should be in one place. |
so it seems that your functions is for magic getter method. I always put that code on the extended model. Logically it's the same, but be warned that your code will be rewritten if you change your DB structure & wants to re-generate the model. you better move your getFunctions to extended models (manually) if you want to be in one place. (which will override your base model if you re-generate it) |
Thanks for the explanation. That is what I am missing most in Yii2. I do not know WHY something is chosen, only that is chosen. Therefore, I can not re-think the decisions and make a correct extension of the thoughts. |
search form & gridview improved, fixes #9 Scrutinizer Auto-Fixes
Where to put model rules()?
Should i put it on base model or extended model?
Do you like to change your generated rules?
I think i'll put it on the extended model?
What do you guys think?
The text was updated successfully, but these errors were encountered: