-
-
Notifications
You must be signed in to change notification settings - Fork 10
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
ModelHandler - Sort class names by psr-4 namespace sorting. #17
Conversation
I could see this being helpful, but I also want to leverage the framework's new By instantiating the model via |
Just read into CI4 Factories, this indeed is a really useful tool and will likely be a much better replacement for the current model gathering. Looking forward to that :) Closing, as this is rather a hacky workaround right now and will not be needed after Schemas next revision. |
Okay, so I will have to sleep over this for one or two days... Added a note to the readme to explain model drafting behavior a little. |
Note: This way, if multiple models exists for a table, namespaces appearing later in the psr4 will overwrite those at the beginning (e.g. models in the App namespace are almost always overwritten). |
That rebase went terrifyingly wrong... |
Just an additional notice on the topic: |
I think this can be closed for now. |
Sounds good! Thanks for the feedback. |
This draft aims to make the loading of models during the
draft()
process more constistent and might also be a small start for #7 .Currently, to merge model names into the schema table, the
ModelHandler
follows this routine:get_declared_classes
.This drawback here is, that
get_declared_classes
returns the class names ordered by their time of instantiation.Therefore, depending on where the
draft()
method is called in the app, Some models will already have loaded (e.g., the 'Myth\Auth\Models\UserModel' when using myth-auth) and the resulting$classes
array is unordered.While this is not a problem as long as every table is only assigned to a single model, in the case of multiple models this can lead to inconsistent schema generation, as depending on the models 'pre-loaded' before the draft, different replacements are done (right now, always the last iterated model is stored in the schema table).
This addition sorts the
$classes
array by the order of the namespaces returned from theautoloader
and hence by the order of the$psr4
config array. #7 states that multiple models are not supported yet, however, I think this addition might still be valuable in the current state, as behavior is now consistent with the user-defined namespace sorting in the$psr4
array.When #7 is implemented in the future, I would think a similar logic will have to be applied to allow for priority ordering.