Closed yoieh closed 4 years ago
@yoieh yeah this is a tricky problem. However if I understand you correctly then it sounds like you need to take advantage of the duplicate fields feature. It was added for this type of use case.
I totally overlooked that feature. It seems to do exactly what I need.
Ha rebuilt my associates using this feature now and it seems to work. Only Issue is that it dose seem to add my duplicate fields when using RestHapi.create()
in my seeder. I'm setting enabelDuplicateFields
to true before using it but I have to add the values manually and have them in my schema
@yoieh please check out these docs for using duplicate fields when calling wrapper methods (e.g. RestHapi.create()
: https://resthapi.com/docs/mongoose-wrapper-methods.html#simulated-rest-calls
I missed that the arguments needs to be in a object to use the "restCall=true" also severer has to be registered in the same script if RestHapi.create({restCall: true})
is used in a seeder script.
Also if auth is used credentials needs to be set as such
{
model,
payload,
Log,
restCall: true,
credentials: { user: _id }`
}
It took some time to understand how it works but i got it to work now with in my seeders and it seriously made my code much less complex. Big tanks to you @JKHeadley !
@yoieh good to hear! I'll try to update the docs to make it more clear. Let me know if you have any suggestions.
Is your feature request related to a problem? Please describe. I'm trying to build a frontend with searchable and sortable tables having one "main" collection with where many of the tables columns are
many_one
associations.Simplified example:
I need to be able to filter on the sub fields for now I have to move the data of sub fields to the main collection to accomplish this.
This means that I have a fields in the main collection that has to be updated if the associations
name
filed is updated and in my project there are even worse nested associations that needs to be accessible from the main field like:And every sub doc has its own table on the frontend. In my solution if sub3.name is updated I now need to update every parent after each other in order and doing this in with the
update: {post: () => RestHapi.update() }
andupdate: {pre: () => payloade.subName = ... }
middleware on each layer.sub3.model
sub2.model
sub1.model
main.model
I'm also setting the "moved fields" on create manually in the
create
middleware on each layer. and now I'm able to filter and search even onsub3Name
from my main collection.Performance wise this is bad really bad if I have many main documents.. and if any fails I'm screwed.
Describe the solution you'd like I need to be able to search and sort by
sub1.name
I'm not sure if this is doable at all even on a lower level..