#1034 ✓resolved
bgentry

PATCH submitted - rails_datamapper gem load order dependency

Reported by bgentry | September 10th, 2009 @ 12:30 AM | in 0.10.2

Ran into an issue with a Datamapper Rails app which was also making use of dm-constraints. The gem load order for rails_datamapper becomes an issue with any dm-more plugins which add hooks to Models.

The specific problem that was occurring was that DataMapper.auto_migrate! would cause "undefined method: Model.auto_migrate_down_with_constraints!" for each Model, including DataMapperStore::Session. Running auto_migrate! directly on one of the model classes, as in "User.auto_migrate!" would not result in an error.

To reproduce this problem, start up a Rails app that uses DataMapper and in the environment.rb config file, load 'rails_datamapper' before loading 'dm-constraints'. This should be sufficient to produce the error.

To fix the issue, load 'dm-core' and all dm plugins explicitly before loading 'rails_datamapper'.

dkubb mentioned that this should be considered a bug, and someone should figure out an approach that works both before or after the adapter is loaded, hence this ticket.

Comments and changes to this ticket

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) October 7th, 2009 @ 01:12 PM

    • Milestone set to 0.10.2
    • State changed from “new” to “accepted”
  • bgentry

    bgentry October 18th, 2009 @ 09:11 PM

    Another bit to add to this..

    I was working on trying to make FactoryGirl's alternate syntaxes work with DataMapper, and I ran into an issue trying to include the submodules which add methods to all DataMapper::Model descendants. If I use DataMapper::Model.append_inclusions(module), the methods are appended to all models properly, but only if the model is loaded after these inclusions are added.

    I've yet to figure out a way to make this behavior work when running my specs, other than an ugly hack to force all models to reload after I run #append_inclusions.

  • bgentry

    bgentry October 18th, 2009 @ 10:32 PM

    • Tag changed from bug, constraints, dm-constraints, rails, rails_datamapper to bug, constraints, dm-constraints, dm-core, patch, rails, rails_datamapper
    • Title changed from “rails_datamapper gem load order dependency” to “rails_datamapper gem load order dependency - PATCH submitted”

    Wrote a fix for this issue. Am I forgetting something or was this really this simple??

    http://github.com/bgentry/dm-core/commit/2e64f793646040b55ce12bb43a...

    All the in-memory specs pass, haven't tested the others since I don't have all the adapters installed.

    @@ -86,6 +86,10 @@ module DataMapper
        def self.append_inclusions(*inclusions)
          extra_inclusions.concat inclusions
          # Add the inclusion to existing descendants
          self.descendants.each do |model|
            inclusions.each {|inclusion| model.send :include, inclusion }
          end
          true
        end
    
  • bgentry

    bgentry October 21st, 2009 @ 02:09 PM

    • Title changed from “rails_datamapper gem load order dependency - PATCH submitted” to “PATCH submitted - rails_datamapper gem load order dependency”
  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) November 10th, 2009 @ 02:18 AM

    • State changed from “accepted” to “resolved”

    (from [a09fa1e558e2e72daa8011a9b544a8250b543e6a]) Fixed Model inclusion/extension appending to work with defined models

    • Added logic to Model#append_inclusions to add inclusions to all existing Model descendants
    • Added logic to Model#append_extensions to add extensions to all existing Model descendants
    • Added specs for behavior of Model.append_extensions and .append_inclusions

    [#1034 state:resolved]

    Signed-off-by: Dan Kubb dan.kubb@gmail.com
    http://github.com/datamapper/dm-core/commit/a09fa1e558e2e72daa8011a...

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

People watching this ticket

Referenced by

Pages