Query condition based on relational data
In the Xano-WeWeb tutorial there is an example for conditional query:
Only show records when user_id = user.ID
I also have a Company database, related to multiple users (team members) who should have access to each others records.
For instance condition for Products database should be:
Show products to users
"Where Company ID in Products = Company ID in Users"
Can you help out setup the condition?
Best Answer
-
You're not using dot notation to get the value that you want inside the record. Currently, the conditional is set to be the whole record in the products_companies_id table is equal to the whole record of the user_company_id table. That's why the condition is not being met.
You want to have something like this:
user_company_id.company_id = products_companies_id.user_id (using dots to retrieve the value of the .company_id and .user_id columns inside those tables
Answers
-
Hi @Phil_Cibocom since you are likely going to have the user be authenticated you can first get the user object then filter your products based on the company the belong to
First, you might have a Get Record from User (looking up by the auth ID)
Then, your Products query all records
WHERE products.company_id == user.company_id
-
Hi Michael,
Thanks for your reply. I tried but having error 'Access denied'.
User database authentication is already disabled. -
Hi @Phil_Cibocom,
The API endpoint needs to be configured as authenticated, not as a public endpoint, allowing the retrieval of the user ID by using the authToken.
-
-
@Phil_Cibocom you can only access auth ID when the endpoint requires authentication.
-
Thanks. I cannot see results with setup as attached but I think we're almost there.
What should I modify to make it work? -
Works! Thanks
Categories
- All Categories
- 53 ? Announcements
- 47 ? Releases
- 37 ? Welcome
- 983 ? Help! I'm a Noob
- 125 ? No-Code Front-Ends
- 633 ? Working with APIs
- 439 ? Transforming data
- 126 ? Connect Xano to ...
- 50 ?? Find an Expert
- 348 ❓Other questions
- 35 ? Security
- 22 ✂️ Snippets
- 19 ? Showcase
- 7 ?️ Xano Chatter
- 62 ? Video Tutorials
- 171 ? Request a feature
- 229 ? Report a Bug
- 19 ? Templates & Extensions
- 7 ? Feedback