avram icon indicating copy to clipboard operation
avram copied to clipboard

Confusing error when calling the wrong preload method

Open jwoertink opened this issue 4 years ago • 2 comments

I'm getting this error, but haven't figured out why yet.

A User has_one stream_approval : StreamApproval

web          |
web          |  141 | UserSerializer.new(UserQuery.new.preload_stream_approval(current_user))
web          |                                         ^----------------------
web          | Error: no overload matches 'UserQuery#preload_stream_approval' with type User
web          |
web          | Overloads are:
web          |  - User::BaseQuery#preload_stream_approval(preload_query : StreamApproval::BaseQuery)
web          |  - User::BaseQuery#preload_stream_approval()
web          |
web          | ---

The strange thing is that it only shows these two overloads, but there's 8 different versions of this method.

jwoertink avatar Jan 16 '21 00:01 jwoertink

@jwoertink You're using the instance method of preload with would return a new user with those associations. You want to use the class level methods to add the preloads to an existing association.

UserQuery.preload_stream_approval(current_user)

matthewmcgarvey avatar Jan 16 '21 00:01 matthewmcgarvey

ohh haha. Ok. Maybe we can figure out a way to make that error message better 🤔

jwoertink avatar Jan 16 '21 01:01 jwoertink