Consider the following code:

  class Artist < Sequel::Model
    one_to_many :albums
  end
  artist = Artist.new
  artist.albums

Currently, that artist.albums call raises a Sequel::Error, since new
model objects cannot have any one_to_many associated objects, since
those require a primary key, which generally isn't set until after the
model object is saved.  This is how the associations code has worked
for a long time, at least since 2.3.0 and probably before then.
Sequel in general is strict by default, and this behavior makes sense
in that it raises an error for impossible conditions.

However, this isn't friendly to code that calls association methods on
model objects without caring if they are new or not (maybe because it
deals with model objects in general).  In that case, you have to add
in exceptions to not call the association methods for new model
objects, which makes the code uglier.

I was talking to sferik online about this issue in regards to
merb_admin, specifically 
http://github.com/sferik/merb-admin/blob/master/app/views/main/_has_many.html.erb.
I actually work around this Sequel behavior in the application I'm
currently working on, and it got me thinking about whether Sequel's
current behavior is best.

I'm currently on the fence.  I like strictness and failing fast, but
this might be getting in the way more than helping.  I'd like to hear
some of your thoughts on the issue.

The proposed behavior would operate like including the following code:

  class Sequel::Model
    def _load_associated_objects(opts)
      opts.returns_array? && new? ? [] : super
    end
  end

So if you have any opinion about this, please post here.

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
-~----------~----~----~----~------~----~------~--~---

Reply via email to