Reputation: 1637
I am trying to figure out a way to create dynamic model types, stored in their own respective collections (for a CMS). I want to be able to define a new "content type" and have it stored in it's own collection, and use a standard Sails model to control each model.
I am trying setting the tableName
before saving and before fetching, however with no success.
So something like this:
(Model) Content:
- id
- createdDate
- contentType
- {n...fields}
(Model) ContentType:
- id
- collection (to which each content object would store)
- name
- fields
- field{n}
- type
- name
- required
- …
I am just not sure how to make that happen in sails.js/waterline
Upvotes: 1
Views: 162
Reputation: 1637
This is not possible, at least not the way I am hoping to do it, according to the Sails GitHub page:
https://github.com/balderdashy/sails/issues/1160
Bummer! If someone has a good solution though, let me know and I will mark it as the solution :)
Upvotes: 1
Reputation: 159
This is a possible solution for sails >=0.11.0: https://github.com/sgress454/sails-hook-autoreload
It sounds like it does exactly what you describe: Reload models on the fly without lowering/re-lifting sails.
So as a basic approach: in your admin interface that you're programming, add a content type and it writes to the /api/models/ folder. But please please please, beware the security issues of this! Then when a model gets created, this hook will detect that and load the new model into memory. Same should happen for altering and removing models, but I haven't tested this so I couldn't tell you.
Upvotes: 2