There are two things I ran across recently that aren't obviously bugs (so I
decided to bring them up here rather than open issues), but do feel like
unexpected behavior.
#1 is minor: Refreshing/reloading an instance of a model when it doesn't
exist in the DB anymore seems like it should probably raise a
Sequel::NoMatchingRow error, rather than what it currently raises, which is
a regular old Sequel::Error.
#2 is a bit bigger: Calling #first on a dataset with associations
eager-loaded doesn't actually eager load them:
require 'sequel'
DB = Sequel.sqlite
DB.create_table :posts do
primary_key :id
end
DB.create_table :comments do
primary_key :id
foreign_key :post_id, :posts
end
class Post < Sequel::Model
one_to_many :comments
end
class Comment < Sequel::Model
many_to_one :post
end
Post.create.add_comment({})
p = Post.eager(:comments).all.first
p.associations # => {:comments=>[#<Comment @values={:id=>1, :post_id=>1}>]}
p = Post.eager(:comments).first
p.associations # => {}
Of course, in this simple case it doesn't make much of a difference, but
with a more complex set of associations to load it would become
significant. In my own case, I'm trying to set up an app to only include
associations in serialized JSON if they've been eager-loaded (to have some
finer control over what associations are serialized in what responses, and
to keep myself honest about eager-loading thoroughly).
This feels very unexpected to me, but I'm not sure if I'm alone, or if
changing this behavior would be considered backwards-incompatible.
Feedback/thoughts welcome!
--
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 http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.