On Dec 16, 7:58 pm, Mike Luu <[email protected]> wrote: > I'm attempting to add a feature to Sequel that allows for controlling > filtering, column selection, and ordering of eagerly loaded > associations at runtime. I was having a hard time trying to construct > the feature purely as a plugin and found I had to edit lib/sequel/ > model/associations.rb. My question is whether or not my changes would > be accepted upstream or if there's a more elegant/simpler way of > accomplishing this.
The general Sequel way to do this would be to have separate associations for each of the different types of eager loading you want to do. That should work unless you must have the ability to use arbitrary association options. See http://pastie.org/private/ueystgaxhc9gcn9ymzaujq for an example. In your code, all of the values you are using are hard coded, so this should be possible. If you must have the ability to use arbitrary options at runtime, currently I can't see a better way to do it. It's a shame there isn't a more elegant way, but I didn't have that use case in mind. The actual eager loading process is fairly decoupled from the main dataset, which is why you have to add calling_ds everywhere. Unfortunately, I don't think it's a good idea to include this into Sequel, as it modifies the number of arguments to the :eager_loader proc, which would break all custom eager loaders (and I don't like hacks like checking proc arity). There would have to be wide support for Sequel users for this patch's inclusion before I would consider it. If you don't mind writing a custom :eager_loader that takes a calling_ds option, and patch eager_load to check the proc arity and include self as the fourth option if the arity is 4, you could probably simplify some of this code, but you'd have to add the custom :eager_loader for every association. If you do have the requirement to use arbitrary options at runtime, I'd be interested in hearing your use case. Jeremy -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sequel-talk?hl=en.
