Project

General

Profile

Actions

Improvement #159

closed

Add validations for self-related associations

Added by liaham about 4 years ago. Updated about 4 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Target version:
Start date:
02/12/2021
Due date:
% Done:

100%

Estimated time:
Compatible Redmine Version:

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

  1. An object cannot have a relation to itself: (a,a) or (b,b) .
  2. 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.
  3. The pair (a,b) is uniqe.
Actions #1

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.
Actions #2

Updated by liaham about 4 years ago

  • Target version set to unreleased
Actions #3

Updated by liaham about 4 years ago

  • Description updated (diff)
Actions #4

Updated by liaham about 4 years ago

  • Status changed from New to In Progress
  • % Done changed from 0 to 60
Actions #5

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.

Actions #6

Updated by liaham about 4 years ago

  • % Done changed from 60 to 100
Actions #7

Updated by liaham about 4 years ago

  • Status changed from In Progress to Closed
Actions #8

Updated by liaham about 4 years ago

  • Assignee set to liaham
Actions #9

Updated by liaham about 4 years ago

  • Target version changed from unreleased to 1.0.0
Actions

Also available in: Atom PDF