lib/couchrest/model/utils/migrate.rb in couchrest_model-2.2.0.beta1 vs lib/couchrest/model/utils/migrate.rb in couchrest_model-2.2.0.beta2
- old
+ new
@@ -57,11 +57,11 @@
# Go through each class that inherits from CouchRest::Model::Base and
# attempt to migrate the design documents.
def all_models(opts = {})
opts.reverse_merge!(activate: true, with_proxies: false)
callbacks = migrate_each_model(find_models)
- callbacks += migrate_each_proxying_model(find_proxying_models) if opts[:with_proxies]
+ callbacks += migrate_each_proxying_model(find_proxying_base_models) if opts[:with_proxies]
activate_designs(callbacks) if opts[:activate]
end
def all_models_and_proxies(opts = {})
opts[:with_proxies] = true
@@ -72,12 +72,12 @@
def find_models
CouchRest::Model::Base.subclasses.reject{|m| m.proxy_owner_method.present?}
end
- def find_proxying_models
- CouchRest::Model::Base.subclasses.reject{|m| m.proxy_method_names.empty?}
+ def find_proxying_base_models
+ CouchRest::Model::Base.subclasses.reject{|m| m.proxy_method_names.empty? || m.proxy_owner_method.present?}
end
def migrate_each_model(models, db = nil)
callbacks = [ ]
models.each do |model|
@@ -89,15 +89,18 @@
end
def migrate_each_proxying_model(models)
callbacks = [ ]
models.each do |model|
- methods = model.proxy_method_names
+ model_class = model.is_a?(CouchRest::Model::Proxyable::ModelProxy) ? model.model : model
+ methods = model_class.proxy_method_names
methods.each do |method|
- puts "Finding proxied models for #{model}##{method}"
+ puts "Finding proxied models for #{model_class}##{method}"
+ model_class.design_doc.auto_update = false
model.all.each do |obj|
proxy = obj.send(method)
callbacks += migrate_each_model([proxy.model], proxy.database)
+ callbacks += migrate_each_proxying_model([proxy]) unless model_class.proxy_method_names.empty?
end
end
end
callbacks
end