Sequel adapter #89

Open
wants to merge 2 commits into
from

Conversation

Projects
None yet
4 participants

I added a Sequel adapter.

Since Sequel doesn't support deferred associations natively, the adapter is slightly more complex than the ActiveRecord adapter.

John Firebaugh added some commits Jul 13, 2011

Is it possible to get this merged in? It would be really nice to have Sequel support in machinist...

Collaborator

benhoskings commented Jan 26, 2013

This would be better packaged as a separate gem, perhaps machinist-sequel—it's cleanly independent of machinist core and this way, the mainenance of one won't affect the other.

Seeing as ActiveRecord is supported as an adapter already, and not really part of the "core", is it not reasonable to have Sequel also supported in the main gem?

Collaborator

benhoskings commented Jan 28, 2013

Well, activerecord should be moved to a separate gem too, but that's a separate job :)

Since the two concerns can be cleanly separated I think separate gems would be better.

On 28/01/2013, at 6:07 PM, Matt Hauck notifications@github.com wrote:

Seeing as ActiveRecord is supported as an adapter already, and not really part of the "core", is it not reasonable to have Sequel also supported in the main gem?


Reply to this email directly or view it on GitHub.

Thanks John for this Sequel adapter. I found one bug in it, that was causing many-to-one associations to render in the database as many-to-many. This was fixed with the following 2 added lines:

   def assign_attribute(attribute, value)
      association = @klass.association_reflection(attribute)
      if association
        if association.returns_array?
          (object.machinist_deferred_associations ||= []) << [association, value]
        elsif value.new?
          value.save(:raise_on_failure => true)
          super
        # NOTE: next 2 lines were necessary to fix a bug
        #  in the sequel adapter.  Without it, many-to-one
        #  relationships are incorrectly rendered in the
        #  database as a many-to-many.  -Dean
        else
          super
        end
      else
        super
      end
    end
 

Here is a spec that recreates the problem:

      RssFeed.blueprint do
        name { Faker::Lorem.word }
      end

      feed = RssFeed.make!
      20.times { Video.make!( :managed_feed => feed  ) }

Without the above fix, 20 RssFeed rows and 20 video rows are created. Total of 40 rows.

With the above fix, 1 RssFeed is created, and 20 videos, all linked back to the common RssFeed. Total of 21 rows.

Dean

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment