diff --git a/lib/stringex/acts_as_url/adapter/base.rb b/lib/stringex/acts_as_url/adapter/base.rb index b8ed8b19..9bf0fe37 100644 --- a/lib/stringex/acts_as_url/adapter/base.rb +++ b/lib/stringex/acts_as_url/adapter/base.rb @@ -18,7 +18,7 @@ def create_callbacks!(klass) end def ensure_unique_url!(instance) - @url_owners = nil + @taken_urls = nil self.instance = instance handle_url! @@ -131,7 +131,7 @@ def url_taken?(url) if settings.url_taken_method instance.send(settings.url_taken_method, url) else - url_owners.any?{|owner| url_attribute_for(owner) == url} + taken_urls.include?(url) end end @@ -196,8 +196,9 @@ def url_owner_conditions @url_owner_conditions end - def url_owners - @url_owners ||= url_owners_class.unscoped.where(url_owner_conditions).to_a + def taken_urls + @taken_urls ||= url_owners_class.unscoped.where(url_owner_conditions). + pluck(settings.url_attribute) end def url_owners_class diff --git a/lib/stringex/acts_as_url/adapter/data_mapper.rb b/lib/stringex/acts_as_url/adapter/data_mapper.rb index 67fdbf63..d77042ea 100644 --- a/lib/stringex/acts_as_url/adapter/data_mapper.rb +++ b/lib/stringex/acts_as_url/adapter/data_mapper.rb @@ -44,8 +44,10 @@ def read_attribute(instance, attribute) instance.attributes[attribute] end - def url_owners - @url_owners ||= url_owners_class.all(:conditions => url_owner_conditions) + def taken_urls + @taken_urls ||= url_owners_class. + all(conditions: url_owner_conditions). + pluck(settings.url_attribute) end def read_attribute(instance, name) @@ -62,4 +64,4 @@ def self.orm_class end end end -end \ No newline at end of file +end