active-fedora 5.5.1 → 5.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +3 -0
- data/lib/active_fedora/associations.rb +11 -8
- data/lib/active_fedora/associations/association_collection.rb +3 -1
- data/lib/active_fedora/base.rb +3 -0
- data/lib/active_fedora/querying.rb +1 -1
- data/lib/active_fedora/relationships.rb +1 -1
- data/lib/active_fedora/solr_service.rb +7 -2
- data/lib/active_fedora/version.rb +1 -1
- data/spec/integration/has_many_associations_spec.rb +33 -0
- data/spec/unit/has_many_collection_spec.rb +1 -2
- metadata +5 -3
data/History.txt
CHANGED
@@ -12,24 +12,27 @@ module ActiveFedora
|
|
12
12
|
|
13
13
|
autoload :AssociationCollection, 'active_fedora/associations/association_collection'
|
14
14
|
autoload :AssociationProxy, 'active_fedora/associations/association_proxy'
|
15
|
+
|
16
|
+
# Clears out the association cache.
|
17
|
+
def clear_association_cache #:nodoc:
|
18
|
+
@association_cache.clear if persisted?
|
19
|
+
end
|
20
|
+
|
21
|
+
# :nodoc:
|
22
|
+
attr_reader :association_cache
|
23
|
+
|
15
24
|
private
|
16
25
|
|
17
26
|
# Returns the specified association instance if it responds to :loaded?, nil otherwise.
|
18
27
|
def association_instance_get(name)
|
19
|
-
|
20
|
-
if instance_variable_defined?(ivar)
|
21
|
-
association = instance_variable_get(ivar)
|
22
|
-
association if association.respond_to?(:loaded?)
|
23
|
-
end
|
28
|
+
@association_cache[name.to_sym]
|
24
29
|
end
|
25
30
|
|
26
31
|
# Set the specified association instance.
|
27
32
|
def association_instance_set(name, association)
|
28
|
-
|
33
|
+
@association_cache[name] = association
|
29
34
|
end
|
30
35
|
|
31
|
-
|
32
|
-
|
33
36
|
module ClassMethods
|
34
37
|
|
35
38
|
def has_many(association_id, options={})
|
@@ -180,7 +180,9 @@ module ActiveFedora
|
|
180
180
|
end
|
181
181
|
|
182
182
|
def construct_query
|
183
|
-
|
183
|
+
clauses = {@reflection.options[:property] => @owner.internal_uri}
|
184
|
+
clauses[:has_model] = @reflection.class_name.constantize.to_class_uri if @reflection.class_name
|
185
|
+
@counter_query = @finder_query = ActiveFedora::SolrService.construct_query_for_rel(clauses)
|
184
186
|
end
|
185
187
|
|
186
188
|
|
data/lib/active_fedora/base.rb
CHANGED
@@ -68,6 +68,7 @@ module ActiveFedora
|
|
68
68
|
# the given namespace.
|
69
69
|
def initialize(attrs = nil)
|
70
70
|
attrs = {} if attrs.nil?
|
71
|
+
@association_cache = {}
|
71
72
|
attributes = attrs.dup
|
72
73
|
@inner_object = UnsavedDigitalObject.new(self.class, attributes.delete(:namespace), attributes.delete(:pid))
|
73
74
|
self.relationships_loaded = true
|
@@ -80,6 +81,7 @@ module ActiveFedora
|
|
80
81
|
|
81
82
|
# Reloads the object from Fedora.
|
82
83
|
def reload
|
84
|
+
clear_association_cache
|
83
85
|
init_with(self.class.find(self.pid).inner_object)
|
84
86
|
end
|
85
87
|
|
@@ -94,6 +96,7 @@ module ActiveFedora
|
|
94
96
|
# post.init_with(DigitalObject.find(pid))
|
95
97
|
# post.properties.title # => 'hello world'
|
96
98
|
def init_with(inner_obj)
|
99
|
+
@association_cache = {}
|
97
100
|
@inner_object = inner_obj
|
98
101
|
unless @inner_object.is_a? SolrDigitalObject
|
99
102
|
@inner_object.original_class = self.class
|
@@ -145,7 +145,7 @@ module ActiveFedora
|
|
145
145
|
# Return the solr clause that queries for this type of class
|
146
146
|
def search_model_clause
|
147
147
|
unless self == ActiveFedora::Base
|
148
|
-
return ActiveFedora::SolrService.construct_query_for_rel(:has_model
|
148
|
+
return ActiveFedora::SolrService.construct_query_for_rel(:has_model => self.to_class_uri)
|
149
149
|
end
|
150
150
|
end
|
151
151
|
end
|
@@ -365,7 +365,7 @@ module ActiveFedora
|
|
365
365
|
subject = :inbound
|
366
366
|
if relationships_desc.has_key?(subject) && relationships_desc[subject].has_key?(relationship_name)
|
367
367
|
predicate = relationships_desc[subject][relationship_name][:predicate]
|
368
|
-
query = ActiveFedora::SolrService.construct_query_for_rel(predicate
|
368
|
+
query = ActiveFedora::SolrService.construct_query_for_rel(predicate => "info:fedora/#{pid}")
|
369
369
|
if relationships_desc.has_key?(subject) && relationships_desc[subject].has_key?(relationship_name) && relationships_desc[subject][relationship_name].has_key?(:solr_fq)
|
370
370
|
solr_fq = relationships_desc[subject][relationship_name][:solr_fq]
|
371
371
|
query << " AND " unless query.empty?
|
@@ -72,8 +72,13 @@ module ActiveFedora
|
|
72
72
|
return uri.gsub(/(:)/, '\\:').gsub(/(\/)/, '\\/')
|
73
73
|
end
|
74
74
|
|
75
|
-
|
76
|
-
|
75
|
+
# Create a query with a clause for each key, value
|
76
|
+
# @param [Hash] args key is the predicate, value is the target_uri
|
77
|
+
def self.construct_query_for_rel(args)
|
78
|
+
clauses = args.map do |predicate, target_uri|
|
79
|
+
"#{solr_name(predicate, :symbol)}:#{escape_uri_for_query(target_uri)}"
|
80
|
+
end
|
81
|
+
clauses.join(" AND ")
|
77
82
|
end
|
78
83
|
|
79
84
|
def self.query(query, args={})
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "When two or more relationships share the same property" do
|
4
|
+
before do
|
5
|
+
class Book < ActiveFedora::Base
|
6
|
+
has_many :collections, :property=>:is_part_of, :class_name=>'Collection'
|
7
|
+
has_many :people, :property=>:is_part_of#, :class_name=>'Person'
|
8
|
+
end
|
9
|
+
|
10
|
+
class Person < ActiveFedora::Base
|
11
|
+
belongs_to :book, :property=>:is_part_of
|
12
|
+
end
|
13
|
+
|
14
|
+
class Collection < ActiveFedora::Base
|
15
|
+
belongs_to :book, :property=>:is_part_of
|
16
|
+
end
|
17
|
+
|
18
|
+
@book = Book.create!#(:collections=>[@collection1, @collection2], :people=>[@person1, @person2])
|
19
|
+
@person1 = Person.create!(:book=>@book)
|
20
|
+
@person2 = Person.create!(:book=>@book)
|
21
|
+
end
|
22
|
+
after do
|
23
|
+
Object.send(:remove_const, :Collection)
|
24
|
+
Object.send(:remove_const, :Person)
|
25
|
+
Object.send(:remove_const, :Book)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "Should only return relationships of the correct class" do
|
29
|
+
@book.reload
|
30
|
+
@book.people.should == [@person1, @person2]
|
31
|
+
@book.collections.should == []
|
32
|
+
end
|
33
|
+
end
|
@@ -3,8 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe ActiveFedora::Associations::HasManyAssociation do
|
4
4
|
it "should be able to replace the collection" do
|
5
5
|
@owner = stub(:new_record? => false, :to_ary => nil, :internal_uri => 'info:fedora/changeme:99')
|
6
|
-
@reflection = stub(:klass => mock.class, :options=>{:property=>'predicate'})
|
7
|
-
#ac = ActiveFedora::Associations::AssociationCollection.new(@owner, @reflection)
|
6
|
+
@reflection = stub(:klass => mock.class, :options=>{:property=>'predicate'}, :class_name=> nil)
|
8
7
|
ac = ActiveFedora::Associations::HasManyAssociation.new(@owner, @reflection)
|
9
8
|
@target = [stub(:to_ary => nil, :new_record? => false, :remove_relationship=>true), stub(:to_ary => nil, :new_record? => false, :remove_relationship=>true), stub(:to_ary => nil, :new_record? => false, :remove_relationship=>true)]
|
10
9
|
ac.target = @target
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active-fedora
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.5.
|
4
|
+
version: 5.5.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2013-01-
|
14
|
+
date: 2013-01-28 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rsolr
|
@@ -442,6 +442,7 @@ files:
|
|
442
442
|
- spec/integration/datastreams_spec.rb
|
443
443
|
- spec/integration/delete_all_spec.rb
|
444
444
|
- spec/integration/full_featured_model_spec.rb
|
445
|
+
- spec/integration/has_many_associations_spec.rb
|
445
446
|
- spec/integration/metadata_datastream_helper_spec.rb
|
446
447
|
- spec/integration/model_spec.rb
|
447
448
|
- spec/integration/mods_article_integration_spec.rb
|
@@ -565,7 +566,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
565
566
|
version: '0'
|
566
567
|
segments:
|
567
568
|
- 0
|
568
|
-
hash:
|
569
|
+
hash: -3856753217323380109
|
569
570
|
requirements: []
|
570
571
|
rubyforge_project: rubyfedora
|
571
572
|
rubygems_version: 1.8.24
|
@@ -605,6 +606,7 @@ test_files:
|
|
605
606
|
- spec/integration/datastreams_spec.rb
|
606
607
|
- spec/integration/delete_all_spec.rb
|
607
608
|
- spec/integration/full_featured_model_spec.rb
|
609
|
+
- spec/integration/has_many_associations_spec.rb
|
608
610
|
- spec/integration/metadata_datastream_helper_spec.rb
|
609
611
|
- spec/integration/model_spec.rb
|
610
612
|
- spec/integration/mods_article_integration_spec.rb
|