Last active
August 29, 2015 14:23
-
-
Save jcoyne/5c654505a2004f54cbe1 to your computer and use it in GitHub Desktop.
Probem with ActiveFedora associations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Collection < ActiveFedora::Base | |
has_many :contributors, inverse_of: :contributorable, as: 'contributorable' | |
accepts_nested_attributes_for :contributors, allow_destroy: true, reject_if: proc { |attributes| attributes['contributor_name'].first.blank? } | |
end | |
class Contributor < ActiveFedora::Base | |
belongs_to :contributorable, predicate: ::RDF::URI.new('http://collections.durham.ac.uk/ns#contributor_to'), | |
class_name: 'ActiveFedora::Base' | |
end | |
Collection.new.association(:contributors).find_target | |
c1 = Collection.create | |
c2 = Collection.create | |
c3 = Collection.create | |
cont1 = Contributor.create | |
cont2 = Contributor.create | |
cont1.contributorable = c1 | |
cont2.contributorable = c2 | |
cont1.save | |
cont2.save | |
# This fails because it returns two results (cont1 & cont2) | |
expect(Collection.new.association(:contributors).find_target).to be_empty | |
=> [#<Contributor id: "41/cf/16/77/41cf1677-c74a-463a-97e0-1163a91d1658", contributorable_id: "70/5e/3d/ed/705e3ded-da2a-4118-99c1-4ed7ce194e81">, #<Contributor id: "8e/b9/f3/63/8eb9f363-7d8a-4fe3-8dc7-ac4a5d5f8f02", contributorable_id: "f2/cc/9f/f2/f2cc9ff2-44e4-451d-b01e-cc63131f180e">] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment