CollectionProxy#count on unsaved parent returns all objects in scope.
This problem only occurs when class_name: 'ActiveFedora::Base' is specified.
class Library < ActiveFedora::Base
has_many :books, predicate: ::RDF::Vocab::DC.isPartOf, class_name: 'ActiveFedora::Base'
end
class Book < ActiveFedora::Base
belongs_to :library, predicate: ::RDF::Vocab::DC.isPartOf
end
Book.create!
Book.create!
Library.new.books.count
#=>2
@jcoyne: Is it acceptable to say that ActiveFedora::Base is not a valid class_name for the association and raise when it is received?
I don't think so. We may want to accept several types of classes that extend AF::Base and this has been the way to do this.
Consider the following:
class Novel < ActiveFedora::Base; end
class Atlas < ActiveFedora::Base; end
library = Library.create
library.books = [Novel.create, Atlas.create]
Yeah, rejecting Base would require the implementer to have some other nominal class (probably extending the same).
class MyApp::Base < ActiveFedora::Base; end
class Novel < MyApp::Base; end
class Atlas < MyApp::Base; end
library = Library.create
library.books = [Novel.create, Atlas.create]
I'm not strongly enamored of it, but I'm not entirely against it since it seems useful in other ways.
@jcoyne: there really isn't a comparably simple ActiveRecord equivalent, though, right? You can't just declare has_many ActiveRecord::Base and then expect to backfill polymorphic associations to anything later, right? There are sound logical reasons to impose more constraint here.