Is it possible to combine two prisma selections to...
# orm-help
b
Is it possible to combine two prisma selections together in one query and
orderBy
the combined result? Meaning...
Copy code
.findFirst({
 where: {
    id:  1
  }, {
   select: {
     something: {...},
     somethingElse: {...}
    }
  }
})
so combining something and somethingElse within here and then
orderBy
both of them all in one query, including pagination
✅ 1
d
your root record is a single item — where do you think you are going to get multiple records to paginate? Paginating sub-records is not a “thing” — if you want to paginate you have to make ‘something’ and ’something else” the root of the query as in
Copy code
something.findFirst({ 
where { foo.id: 1}
take: 4,
skip: 5,
});
You cannot take multiple tables and treat them as a single set of records in SQL without a significant restrictions (https://www.postgresqltutorial.com/postgresql-tutorial/postgresql-union/). You can do so procedurally by 1. creating a temporary table with fields that accept values from both sources (and maybe a “source_table” field for reference) 2. dumping data from two queries into the temp table and 3. querying it; however the temporary table will not persist across queries, meaning, the net work is a lot greater than simply pulling all the relevant data into javaScript and paginating it. A third option is to 1 create a permanent denormalized table with fields that accept values from both sources 2 dumping all relevant data into it and 3. querying the denormed table but the basic problem here is you are dealing with a grid-based system and trying to make it act like a polymorphic class — that is going to take a significant amount of carrying by you.