Actions
Improvement #159
closedAdd validations for self-related associations
Start date:
02/12/2021
Due date:
% Done:
100%
Estimated time:
Compatible Redmine Version:
Pull Request Link:
Description
Self-related Relation¶
A relation between two objects of the same model (ProjectType or Project) is defined as ordered pair:
(a,b) != (b,a)
The left object of the pair is the superordinate (guest) and the right object is the subordinate (host).
- Project types uses superordinate and subordinate notation.
- Projects uses guest and host notation.
Resulting Rules concerning Data Persistence¶
- An object cannot have a relation to itself:
(a,a) or (b,b)
. - An oject cannot have a subordinated relation to its superordinated object, what would cause a circular reference:
(a,b) and (b,a)
. That is, a relation is either(a,b) or (b,a)
, but not both. The preferred definition, what should be saved, is from superordinated object to subordinated object. - The pair
(a,b)
is uniqe.
Updated by liaham about 4 years ago
Notes on what does not work out of the box¶
- It is not possible to validate the objects of a collection all at ones. That is, each object is validated sequentially.
- It is not possible to validate both the assignee and assigned object at the same time for comparing its project_type_id.
Updated by liaham about 4 years ago
- Status changed from New to In Progress
- % Done changed from 0 to 60
Updated by liaham about 4 years ago
Solution for validating associated objects¶
For :has_many
associations there are callbacks like :before_remove
and before_add
. These callback can be used to access both, the association and its object. In case of an invalid record one can add an error and raise an exception which needs to be catched in the respective controller.
Updated by liaham about 4 years ago
- Target version changed from unreleased to 1.0.0
Actions