Singleton resources
Singleton being defined as: "There is only ever one, no more and no less."
Is there a recommended pattern? So far I have something that is basically an
- Does not allow anybody to call
- Automatically populates the record if it does not exist with the bare
- Automatically fetches the single record using in
This is somewhat less than ideal. Would there be interest in supporting something like this more explicitly?
The primary difference in behaviour to other resource types are:
- They cannot be created or destroyed.
- They can only be read or updated.
- It is unnecessary to pass an instance of them to update actions.
- There is no sense in filtering them (but still sense in determining which attributes to select).
Otherwise, many of the same things that make sense for other types of resources make sense for singletons as well, and there are a fair number of situations where the thing that best describes my domain is a singleton.
Is there a recommended pattern? So far I have something that is basically an
Ash.Resource with create, read and update actions and:- Does not allow anybody to call
create, and does not expose it via frontend channels;- Automatically populates the record if it does not exist with the bare
create using authorize?: false;- Automatically fetches the single record using in
update.This is somewhat less than ideal. Would there be interest in supporting something like this more explicitly?
The primary difference in behaviour to other resource types are:
- They cannot be created or destroyed.
- They can only be read or updated.
- It is unnecessary to pass an instance of them to update actions.
- There is no sense in filtering them (but still sense in determining which attributes to select).
Otherwise, many of the same things that make sense for other types of resources make sense for singletons as well, and there are a fair number of situations where the thing that best describes my domain is a singleton.
