Wednesday 27 May 2020

knex, postgress, receiving wrong info?

hi, i'm a selftaught noob with bad english skillsi'm having a problem where i'm not receiving the data that i'm expectingi have a database with 3 tables,object table => wich contain objects that can have multiple contacts,contactPerson table => wich contains contacts that can be the contact person for multiple objectsso i thought this was a "many to many" relation so i made a "linker" table wich contains the 'object_id' & 'contactPerson_id' as foreign keysconst joinFields =['object_name','serial_nr','contact_name','email','phone_nr']; async get(param){ const object= db('object') .join('linker','object.id','=','linker.object_id') .join('contactPerson','linker.contactPerson_id','=','contactPerson.id') .where(object_name','ilike','%'+param+'%') .orWhere('serial_nr','ilike','%'+param+'%') .select(joinFields); return object; }, when i run this code i expect to recieve one object that matches the name/serial with all the contact persons for that objectinstead i receive 2 objects (the same one) but each time with a different contactPersonwhat am i missing, wich direction should i search to create it like i want it (1 object with all the contacts)thnx

Submitted May 27, 2020 at 11:19AM by sageza

No comments:

Post a Comment