On Friday, April 21, 2017 at 12:01:20 PM UTC-7, Jeremy Evans wrote:
>
> Currently, if you define an association such as:
>
> Foo.one_to_many :bars
>
> It adds the following methods to Foo instances:
>
> # read only methods
> bars
> bars_dataset
>
> # modification methods
> add_bar
> remove_bar
> remove_all_bars
>
> For the majority of associations, users generally only call the read only
> methods. There are certainly cases where users call the modification
> methods, but I'm guessing less than half of associations actually use them.
>
> I'm considering deprecating the automatic addition of modification
> methods, and making associations only define the read only methods by
> default in Sequel 5. To enable the modification methods for a single
> association, you could do:
>
> Foo.one_to_many :bars, :read_only=>false
>
> You could also do:
>
> Sequel::Model.default_association_options[:read_only] = false
>
> before loading your models to default to the Sequel 4 behavior of
> automatically creating modification methods for each association.
>
> For many_to_one/one_to_one associations, I'm leaning towards still
> defining the setter method by default, since it is only a single method and
> is probably more commonly used than the one_to_many/many_to_many
> modification methods.
>
> In one of my projects:
>
> 104 one_to_many/many_to_many associations
> 26 needing modification methods (many only during testing and not during
> production)
> 78 not needing them
> ~800KB memory saved by not defining unnecessary modification methods
>
> I would like to get some feedback from the community before making the
> final decision.
>
After doing some more testing on different applications, I've found that
the majority of them will not benefit from this, and this change ends up
breaking most of them (though fixing it is fairly easy).
I've decided not to change the default behavior. However, if you want to
turn off the modification methods on a per-association type basis, I have
added a default_association_type_options method that allows setting of
default options per association type. So you can get this behavior via:
opts = Sequel::Model.default_association_type_options
opts[:one_to_many] = opts[:many_to_many] = {:read_only=>true}
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.