lighthouse icon indicating copy to clipboard operation
lighthouse copied to clipboard

`@with` inherit `@orderBy` clause of original query

Open exodusanto opened this issue 2 years ago • 1 comments

Describe the bug

Seems like the @with inherit @orderBy clause of original query, so if the column doesn't exists also in relation it will fail the query

Maybe the solution is to only add ->reorder() on the builder

Expected behavior/Solution

The ->load should not contain orderBy clause

Steps to reproduce

  1. Create a @hasMany relation on a model
  2. Add @orderBy to args
  3. Add @with to another relation on the same model

Output/Logs

Click to expand
select
  `users`.*,
  `circles`.`user_id` as `pivot_user_id`,
  `circles`.`peer_id` as `pivot_peer_id`,
  `circles`.`created_at` as `pivot_created_at`,
  `circles`.`updated_at` as `pivot_updated_at`
from
  `users`
  inner join `circles` on `users`.`id` = `circles`.`peer_id`
where
  `circles`.`user_id` in (31)
order by
  `created_at` desc

Lighthouse Version v6.22.0

exodusanto avatar Nov 17 '23 08:11 exodusanto

Could you add a failing test case? Not exactly sure where best to put it since multiple directives are concerned, feel free to choose among WithDirectiveTest, OrderByDirectiveDBTest or HasManyDirectiveTest:

spawnia avatar Dec 05 '23 11:12 spawnia