So trying to figure out how to fetch associations from a service without dups came up with this.
Seems to work and wanted to share to help anyone with similar needs - or better yet get feedback from Marshall and better minds on where this will create problems down the road.
So I have Postgres/Sequelize/Feathers on the backend with the following resources.
Customers
Companies
Contacts
Phones
Emails
Addresses
A Customer has 1:1 associations to either a Companies record or a Contacts (not both)
The Companies record and Contacts record have 1:1 associations with Phones, Emails and Addresses
My goal is to fetch the customers and show them in a Quasar Table with the associated contact or company name, email address, phone number and address.
First I expect a lot of Customers so setup my Feathers server services to turn off pagination in my before find hook on each of the services before hook.
Basically, I setup some arrays to hold and filter out duplicated associated data ids and perform $in queries to fetch the data matching those id's. It looks something like this:
PS: I am a freshman coder at best, so likely this code is bloated, should have used ES6 maps or whatever for arrays but it seems to work. Comments on how to tune this would be appreciated
So trying to figure out how to fetch associations from a service without dups came up with this. Seems to work and wanted to share to help anyone with similar needs - or better yet get feedback from Marshall and better minds on where this will create problems down the road.
So I have Postgres/Sequelize/Feathers on the backend with the following resources.
Customers
Companies
Contacts
Phones
Emails
Addresses
A Customer has 1:1 associations to either a Companies record or a Contacts (not both)
The Companies record and Contacts record have 1:1 associations with
Phones
,Emails
andAddresses
My goal is to fetch the customers and show them in a Quasar Table with the associated contact or company name, email address, phone number and address.
First I expect a lot of Customers so setup my Feathers server services to turn off pagination in my before find hook on each of the services
before
hook.I setup my Customer List .vue file using the (Renderless Data Components)[https://vuex.feathersjs.com/data-components.html#renderless-data-components] pattern
Basically, I setup some arrays to hold and filter out duplicated associated data ids and perform
$in
queries to fetch the data matching those id's. It looks something like this: