On Wed, Apr 13, 2022 at 7:21 AM Martín Fernández <fmarti...@gmail.com> wrote:
> Hello, > > We stumbled upon a bug in our system due to a misunderstanding on how > custom datasets work when they are defined in models. > > We have the following example: > > ``` > class User > one_to_many :active_role_assignments, class: RoleAssignment.name do |ds| > ds.active > end > end > ``` > > In another place of the code we are doing something close to this: > > ``` > User.association_join(:active_role_assignments) > ``` > > We were under the impression that `ds.active` was going to considered but > that doesn't seem to be true. > > Is there a way to make Sequel consider the custom dataset of the relation? > association_join uses eager_graph internally, and eager_graph cannot consider association blocks, since it works on joined datasets. You should use an appropriate :graph_conditions option for the active_role_assignments association. I realize Sequel's behavior is suboptimal here. I added the auto_restrict_eager_graph plugin ( https://sequel.jeremyevans.net/rdoc-plugins/classes/Sequel/Plugins/AutoRestrictEagerGraph.html) in Sequel 5.55.0 which will not allow the use of eager_graph (and therefore association_join) for associations with blocks but without :graph_* options. This is likely to become the default behavior in Sequel 6. Thanks, Jeremy -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to sequel-talk+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sequel-talk/CADGZSSfuRLxFZ4ySAa03bx-nfq0VR3apt%3DJPTuvmNKUUmG4UVg%40mail.gmail.com.