-
Notifications
You must be signed in to change notification settings - Fork 37
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
using dynamic models #82
Comments
It already does pull model types dynamically: https://github.com/DockYard/ember-admin/blob/master/addon/routes/admin.js#L10 but the models do need to be registered with the admin store: https://github.com/DockYard/ember-admin/blob/master/addon/stores/admin.js you are likely only making your primary store aware of them |
The admin store is here: https://github.com/DockYard/ember-admin/blob/master/app/initializers/admin.js#L4 FWIW, this path is out of date as the primary ember store has been changed to |
Thanks @bcardarella if I understand you correct I have try to change that to service:store:admin and now I get this error
|
no, I was talking about a change I will likely make in the future. For the time being you should use |
How do I register them with the admin store? |
How are you getting the primary store to recognize the models? |
I get store from the service by doing something like this
then I have function in the service lets call it generateModels() where inside that I create an attribute object with all the attributes and their types from the schema like
then inside the function I get the store and register the tableColumns
obviously there is loop and I do the same for all the models inside the schema. |
you'll have to do something similar: let adminStore = getOwner(this).lookup('store:admin');
adminStore.register('model:user', DS.Model.extend(tableColumns)); |
Perfect I think there is only one little issue left here I get this error
I am using it inside a service does that make any difference when I call getOwner(this) ? |
Oh, it looks like it just registers on the owner which should be OK. I'll reopen this and see why its not getting the new models. Just to be clear: is your primary store getting these dynamic models? |
Thanks, Yes my primary model works fine, also all the hasMany and BelongTo relations work |
no, I'm asking if these models are accessible via your primary store? |
well when I define them, then I can use all those models to create and load data etc. However ember uses lazy so they are not created until the first record is created if this is what you are asking. did I answer the question yet? |
based upon a small test, it definitely pulls in the models dynamically. Assuming the route model hook isn't cached in any way. Would you be able to provide an example that reproduces the problem so I can see what is happening? |
you see I have created a file for user model only because I need that model before user register and that works fine with ember-admin. However all the other dynamically create models are not available . At what point it pulls the models? I only register them after user login successfully. Could it be that at that point it is too late to register them ? I will see if I can make an example. |
Unclear atm. The models would definitely have to be registered prior to hitting the admin interface. |
if it helps this is the error I get at the moment when I try to navigate to admin/:model
which I think is from this file : https://github.com/DockYard/ember-admin/blob/42aa065de33d766b5958d05ba3673f81c12e90f4/addon/mixins/model-records/model-record.js |
Ah I think I know what is the issue, it is to do with the type. Could be because I have introduce my own type? |
It seems models are created but types are not recognised. |
ignore my comments above, it has nothing to do with the types I am creating but still don't know why. but the error |
@bcardarella any idea what is going wrong that I am getting the error above? |
I need an example to work with |
ok I will put together something thanks :) please keep this issue open and I will make something. |
hi @bcardarella sorry I couldn't get around this earlier. I would highly appreciate if you could please have a look and see why you think ember admin doesn't work. Many thanks. |
@bcardarella I know it has been easter holiday but I was wondering if you had a chance to look at this yet? |
I am creating my models dynamically after loading the schema from the server using
Ember.getOwner(store).register('model: modelName', DS.Model.extend(attributes));
It seems this addon need the actual files for models to be bale to create the models. Is there anyway around that?
Is there anyway to add them into the store which ember-admin use at the same time ?
The text was updated successfully, but these errors were encountered: