How to do an OR between associated model searches? #17286
Unanswered
TannerS
asked this question in
Help & Questions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have asked my question here with no help
https://stackoverflow.com/questions/78318113/do-associated-models-where-clauses-act-as-an-and-between-the-models
But i will try to also explain here in a summary.
I have a model that records submissions for a api call. that model has 2 associated models to it linked to it via a fk. So model a exist, and 2 other models b and c that both have a fk via column a_Id.
In my situation, the tables all work together to display data in a table but i need all data to be searchable. SO what i did was something like this... if user types in a search term, i put that into a where clause for all models. For simplicity, i will only show one column being searched in each
pretend im searching for a number in the search bar of the table and its an id that can belong to any of the tables, since the tables are all mixed together into displaying data in this table
Now i thought this would work, but what i think is happening, (and my knowldge of sql is limited as i learn) is i wanna return the joined table of all three models, if the search query exist in ONE of the models. so its like, if search term equals the columns i search for in a, return the entire join between a,b, and c. same for if i find search term in model b, return all the joined data between all 3 tables, and same for model c.
i thought of breaking out the queries however, im also doing pagination and that method breaks the pagination since im using orderby, sortby and using the total results in the table with the amount per page. and doing multiuple queries throws that off
so am what i want possible? I will warn i did get this working in another table on our service but that one only has 2 tables, one main one and one associated one, while this one has 3 models. I will also add, i think what is happening is this is doing an and, meaning it wont return the joined results unless search is in a AND b AND c, where i want a OR b OR c.
So if i could please get some help, thank you!
Beta Was this translation helpful? Give feedback.
All reactions