#to_param returns nil on an unpersisted object
The implementation in ActiveModel checks for persisted? and I don't think we need to do that:
https://github.com/rails/rails/blob/master/activemodel/lib/active_model/conversion.rb#L81
The ActiveModel logic is that the id is not authoritative unless the object has been persisted, right? Which makes sense, for ActiveRecord. Out situation is more complicated:
- if we mint our own IDs, it happens before persistence, so we can respond accurately, but
- if we are relying on Fedora persistence to auto-mint an ID, then we cannot respond accurately. We are in the same position as ActiveRecord then.
Am I understanding correctly?
@atz Even more complicated than that, I think? There are (at least) two mechanisms for setting an ID on an AF::Base object:
- Pass it in when constructed, via the
id: 'whatever'attribute. In this case, the ID is held in an in-memory LdpResource object (based on an AT::Resource, IIRC). In practice, though, I've only seen this done in tests so that we can predict IDs in advance. - The pattern used by AF::Noid, which may pre-date the ability to pass an ID into the constructor, is to override AF's
#assign_idmethod. This method is not called until#saveis called. So ID minting, a la AF::Noid, happens at the point of persistence.
Mostly this would just be for testing, so that we could use unpersisted models in tests. Maybe we should just use mock_model instead in this case. That mocks persisted? to return true.