martenframework / marten

The pragmatic web framework.
https://martenframework.com
MIT License
405 stars 23 forks source link

Ensure `in` predicates can be used with arrays of model records #157

Closed ellmetha closed 6 months ago

ellmetha commented 7 months ago

Description

It appears it's not possible to use the in predicate to filter a many_to_one or one_to_one field from an array of records. For example, the following query set is not possible presently and results in a compilation error:

profiles = [Profiles::Profile.first!, Profiles::Profile.last!]
Blogging::Article.filter(author__in: profiles)

Presently, the only way to write this query set would be to filter using an array of IDs:

profiles = [Profiles::Profile.first!, Profiles::Profile.last!]
Blogging::Article.filter(author_id__in: profiles.map(&.pk))

Let's improve this by making it possible to filter relationship fields like many_to_one or one_to_one fields using an array of model records.