In the documentation the smart field example is a concatenation of this same collection’s fields. But as you can see, my smart field is not based on the collection’s fields, but the identities collection.
I wonder how I can reach out my identities’ fields to match my query terms (the searchCondition object)
Hi @JeremyV !
The let s = models.sequelize; is useless here you are right.
In the example @arnaud gave, the important part is the addition of the user model:
Here we use the include statement to make a join on the user table (just as you did for the get).
From there, you can use the collection in your search statement
Way better @vince ! It does not crash anymore even though it does not return any result yet.
Here is an example of the generated query :
SELECT (...)
FROM "public"."contracts" AS "contracts"
LEFT OUTER JOIN "public"."places" AS "place"
ON "contracts"."place_id" = "place"."id"
INNER JOIN "public"."identities" AS "identity"
ON "contracts"."identity_id" = "identity"."id"
AND ("identity"."last_name" LIKE '%herbaut%'
AND "identity"."first_name" LIKE '%undefined%')
WHERE ((lower("contracts"."display_name") LIKE lower('%herbaut%')
OR lower("contracts"."customer_reference_number") LIKE lower('%herbaut%')
OR lower("contracts"."customer_key") LIKE lower('%herbaut%')
OR lower("contracts"."sergic_vip_label") LIKE lower('%herbaut%')))
ORDER BY "contracts"."id" DESC LIMIT 10 OFFSET 0;
It seems to me that the identity fields are not being searched since I don’t find them in the WHERE statement.
SELECT (...)
LEFT OUTER JOIN "public"."places" AS "place"
ON "contracts"."place_id" = "place"."id"
INNER JOIN "public"."identities" AS "identity"
ON "contracts"."identity_id" = "identity"."id"
AND ("identity"."last_name" ILIKE '%32146%' OR "identity"."first_name" ILIKE '%32146%')
WHERE (("contracts"."id" = 32146
OR lower("contracts"."display_name") LIKE lower('%32146%')
OR "contracts"."amount" = 32146
OR "contracts"."parcel_sergic_id" = 32146
OR lower("contracts"."customer_reference_number") LIKE lower('%32146%')
OR lower("contracts"."customer_key") LIKE lower('%32146%')
OR "contracts"."invited_count" = 32146
OR "contracts"."sergic_vip_code" = 32146
OR lower("contracts"."sergic_vip_label") LIKE lower('%32146%')
OR "contracts"."report_account_entry_amount" = 32146
OR "contracts"."coowner_amount" = 32146
OR "contracts"."pending_amount" = 32146))
ORDER BY "contracts"."id" DESC LIMIT 10 OFFSET 0;
Another one :
SELECT (...)
FROM "public"."contracts" AS "contracts"
LEFT OUTER JOIN "public"."places" AS "place"
ON "contracts"."place_id" = "place"."id"
INNER JOIN "public"."identities" AS "identity"
ON "contracts"."identity_id" = "identity"."id"
AND ("identity"."last_name" ILIKE '%dunet%' OR "identity"."first_name" ILIKE '%dunet%')
WHERE ((lower("contracts"."display_name") LIKE lower('%dunet%')
OR lower("contracts"."customer_reference_number") LIKE lower('%dunet%')
OR lower("contracts"."customer_key") LIKE lower('%dunet%')
OR lower("contracts"."sergic_vip_label") LIKE lower('%dunet%')
OR lower("place"."display_name") LIKE lower('%dunet%')
OR lower("place"."ics_code") LIKE lower('%dunet%')
OR lower("place"."picture_name") LIKE lower('%dunet%')
OR lower("place"."sergic_offer") LIKE lower('%dunet%')
OR lower("place"."sergic_id_full") LIKE lower('%dunet%')
OR lower("place"."invite_url") LIKE lower('%dunet%')
OR lower("place"."wp_code") LIKE lower('%dunet%')
OR lower("place"."description") LIKE lower('%dunet%')
OR lower("place"."siret") LIKE lower('%dunet%')
OR lower("place"."registration_number") LIKE lower('%dunet%')
OR lower("place"."dpe") LIKE lower('%dunet%')))
ORDER BY "contracts"."id" DESC LIMIT 10 OFFSET 0;
dunet/DUNET or any of its substrings doesn’t work. And CLAUDINE does not work either.
maxime, of any of its substrings, does work, whether it is capital or lower case.
But surprisingly, the string HERBAUT (which is my test data, maxime’s lastname) does NOT.