martenframework/marten

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

ellmetha opened this issue · 0 comments

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.