doc/book/en/B0012-schema-definition.en.txt
author sylvain.thenault@logilab.fr
Mon, 04 May 2009 13:18:38 +0200
branchtls-sprint
changeset 1642 12a98b17fb05
parent 1641 2c80b09d8d86
permissions -rw-r--r--
fix tests
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
     1
.. -*- coding: utf-8 -*-
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
     2
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
     3
Entity type definition
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
     4
----------------------
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
     5
1163
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
     6
An entity type is defined by a Python class which inherits from `EntityType`.
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
     7
The class definition contains the description of attributes and relations
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
     8
for the defined entity type.
1352
9fae16f3e068 [doc] Explicitely name the module in which we define schema to distinguish it from entities.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1222
diff changeset
     9
The class name corresponds to the entity type name. It is exepected to be
9fae16f3e068 [doc] Explicitely name the module in which we define schema to distinguish it from entities.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1222
diff changeset
    10
defined in the module ``mycube.schema``.
9fae16f3e068 [doc] Explicitely name the module in which we define schema to distinguish it from entities.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1222
diff changeset
    11
1163
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
    12
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
    13
For example ::
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    14
1159
16a426d214ae use english example names
Emile Anclin <emile.anclin@logilab.fr>
parents: 301
diff changeset
    15
  class Person(EntityType):
301
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 292
diff changeset
    16
    """A person with the properties and the relations necessary for my
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    17
    application"""
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    18
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    19
    last_name = String(required=True, fulltextindexed=True)
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    20
    first_name = String(required=True, fulltextindexed=True)
1163
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
    21
    title = String(vocabulary=('Mr', 'Mrs', 'Miss'))
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    22
    date_of_birth = Date()
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    23
    works_for = SubjectRelation('Company', cardinality='?*')
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    24
1163
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
    25
1442
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    26
The entity described above defines three attributes of type String,
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    27
last_name, first_name and title, an attribute of type Date for the date of
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    28
birth and a relation that connects a `Person` to another entity of type
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    29
`Company` through the semantic `works_for`.
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    30
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    31
The name of the Python attribute corresponds to the name of the attribute
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    32
or the relation in `CubicWeb` application.
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    33
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    34
Built-in types for attributes
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    35
`````````````````````````````
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    36
1442
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    37
All `CubicWeb` built-in types are available : `String`, `Int`, `Float`,
1641
2c80b09d8d86 backport default
sylvain.thenault@logilab.fr
parents: 1477 1598
diff changeset
    38
`Decimal`, `Boolean`, `Date`, `Datetime`, `Time`, `Interval`, `Byte`
1442
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    39
and `Password`.
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    40
They are implicitely imported (as well as the special the function "_"
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    41
for translation :ref:`internationalization`).
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    42
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    43
An attribute is defined in the schema as follows::
1641
2c80b09d8d86 backport default
sylvain.thenault@logilab.fr
parents: 1477 1598
diff changeset
    44
1442
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    45
    attr_name = attr_type(properties*)
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    46
1442
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    47
where `attr_type` is one of the type listed above and `properties` is
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    48
a list of  the attribute needs to statisfy (see :ref:`properties`
1641
2c80b09d8d86 backport default
sylvain.thenault@logilab.fr
parents: 1477 1598
diff changeset
    49
for more details).
1442
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    50
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    51
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    52
Meta-data
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    53
`````````
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    54
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    55
Each entity type has at least the following meta-relations :
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    56
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    57
  - `eid` (`Int`)
1641
2c80b09d8d86 backport default
sylvain.thenault@logilab.fr
parents: 1477 1598
diff changeset
    58
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    59
  - `creation_date` (`Datetime`)
1641
2c80b09d8d86 backport default
sylvain.thenault@logilab.fr
parents: 1477 1598
diff changeset
    60
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    61
  - `modification_date` (`Datetime`)
1641
2c80b09d8d86 backport default
sylvain.thenault@logilab.fr
parents: 1477 1598
diff changeset
    62
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1222
diff changeset
    63
  - `created_by` (`CWUser`) (which user created the entity)
1641
2c80b09d8d86 backport default
sylvain.thenault@logilab.fr
parents: 1477 1598
diff changeset
    64
2c80b09d8d86 backport default
sylvain.thenault@logilab.fr
parents: 1477 1598
diff changeset
    65
  - `owned_by` (`CWUser`) (to whom the entity belongs; by default the
1163
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
    66
     creator but not necessary, and it could have multiple owners)
1641
2c80b09d8d86 backport default
sylvain.thenault@logilab.fr
parents: 1477 1598
diff changeset
    67
1477
b056a49c16dc backport default branch
sylvain.thenault@logilab.fr
parents: 1398 1463
diff changeset
    68
  - `is` (`CWEType`) (of which type the entity is)
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    69
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    70
1163
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
    71
* relations can be defined by using `ObjectRelation` or `SubjectRelation`.
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
    72
  The first argument of `SubjectRelation` or `ObjectRelation` gives respectively
1641
2c80b09d8d86 backport default
sylvain.thenault@logilab.fr
parents: 1477 1598
diff changeset
    73
  the object/subject entity type of the relation. This could be :
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    74
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    75
  * a string corresponding to an entity type
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    76
1163
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
    77
  * a tuple of string corresponding to multiple entity types
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    78
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    79
  * special string such as follows :
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    80
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    81
    - "**" : all types of entities
1641
2c80b09d8d86 backport default
sylvain.thenault@logilab.fr
parents: 1477 1598
diff changeset
    82
    - "*" : all types of non-meta entities
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    83
    - "@" : all types of meta entities but not system entities (e.g. used for
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    84
      the basic schema description)
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    85
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    86
* it is possible to use the attribute `meta` to flag an entity type as a `meta`
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    87
  (e.g. used to describe/categorize other entities)
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    88
1442
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    89
Optionnal properties
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    90
````````````````````
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    91
.. _properties:
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    92
db4e2508082b [doc] Begin improvement of schema definition.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1352
diff changeset
    93
1641
2c80b09d8d86 backport default
sylvain.thenault@logilab.fr
parents: 1477 1598
diff changeset
    94
* optional properties for attributes and relations :
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    95
1163
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
    96
  - `description` : a string describing an attribute or a relation. By default
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    97
    this string will be used in the editing form of the entity, which means
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    98
    that it is supposed to help the end-user and should be flagged by the
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
    99
    function `_` to be properly internationalized.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   100
1163
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
   101
  - `constraints` : a list of conditions/constraints that the relation has to
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   102
    satisfy (c.f. `Contraints`_)
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   103
1163
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
   104
  - `cardinality` : a two character string which specify the cardinality of the
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   105
    relation. The first character defines the cardinality of the relation on
1641
2c80b09d8d86 backport default
sylvain.thenault@logilab.fr
parents: 1477 1598
diff changeset
   106
    the subject, and the second on the object. When a relation can have
1163
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
   107
    multiple subjects or objects, the cardinality applies to all,
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
   108
    not on a one-to-one basis (so it must be consistent...). The possible
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
   109
    values are inspired from regular expression syntax :
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   110
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   111
    * `1`: 1..1
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   112
    * `?`: 0..1
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   113
    * `+`: 1..n
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   114
    * `*`: 0..n
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   115
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   116
  - `meta` : boolean indicating that the relation is a meta-relation (false by
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   117
    default)
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   118
1641
2c80b09d8d86 backport default
sylvain.thenault@logilab.fr
parents: 1477 1598
diff changeset
   119
* optional properties for attributes :
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   120
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   121
  - `required` : boolean indicating if the attribute is required (false by default)
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   122
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   123
  - `unique` : boolean indicating if the value of the attribute has to be unique
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   124
    or not within all entities of the same type (false by default)
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   125
1641
2c80b09d8d86 backport default
sylvain.thenault@logilab.fr
parents: 1477 1598
diff changeset
   126
  - `indexed` : boolean indicating if an index needs to be created for this
1463
136756fff6fb [doc] s/usefull/useful/
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 1442
diff changeset
   127
    attribute in the database (false by default). This is useful only if
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   128
    you know that you will have to run numerous searches on the value of this
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   129
    attribute.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   130
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   131
  - `default` : default value of the attribute. In case of date types, the values
1163
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
   132
    which could be used correspond to the RQL keywords `TODAY` and `NOW`.
1641
2c80b09d8d86 backport default
sylvain.thenault@logilab.fr
parents: 1477 1598
diff changeset
   133
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   134
  - `vocabulary` : specify static possible values of an attribute
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   135
1641
2c80b09d8d86 backport default
sylvain.thenault@logilab.fr
parents: 1477 1598
diff changeset
   136
* optional properties of type `String` :
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   137
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   138
  - `fulltextindexed` : boolean indicating if the attribute is part of
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   139
    the full text index (false by default) (*applicable on the type `Byte`
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   140
    as well*)
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   141
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   142
  - `internationalizable` : boolean indicating if the value of the attribute
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   143
    is internationalizable (false by default)
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   144
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   145
  - `maxsize` : integer providing the maximum size of the string (no limit by default)
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   146
1641
2c80b09d8d86 backport default
sylvain.thenault@logilab.fr
parents: 1477 1598
diff changeset
   147
* optional properties for relations :
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   148
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   149
  - `composite` : string indicating that the subject (composite == 'subject')
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   150
    is composed of the objects of the relations. For the opposite case (when
1641
2c80b09d8d86 backport default
sylvain.thenault@logilab.fr
parents: 1477 1598
diff changeset
   151
    the object is composed of the subjects of the relation), we just set
1163
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
   152
    'object' as value. The composition implies that when the relation
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   153
    is deleted (so when the composite is deleted), the composed are also deleted.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   154
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   155
Contraints
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   156
``````````
1163
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
   157
By default, the available constraint types are :
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   158
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   159
* `SizeConstraint` : allows to specify a minimum and/or maximum size on
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   160
  string (generic case of `maxsize`)
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   161
1641
2c80b09d8d86 backport default
sylvain.thenault@logilab.fr
parents: 1477 1598
diff changeset
   162
* `BoundConstraint` : allows to specify a minimum and/or maximum value on
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   163
  numeric types
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   164
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   165
* `UniqueConstraint` : identical to "unique=True"
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   166
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   167
* `StaticVocabularyConstraint` : identical to "vocabulary=(...)"
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   168
1163
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
   169
* `RQLConstraint` : allows to specify a RQL query that has to be satisfied
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   170
  by the subject and/or the object of the relation. In this query the variables
1641
2c80b09d8d86 backport default
sylvain.thenault@logilab.fr
parents: 1477 1598
diff changeset
   171
  `S` and `O` are reserved for the entities subject and object of the
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   172
  relation.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   173
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   174
* `RQLVocabularyConstraint` : similar to the previous type of constraint except
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   175
  that it does not express a "strong" constraint, which means it is only used to
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   176
  restrict the values listed in the drop-down menu of editing form, but it does
1163
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
   177
  not prevent another entity to be selected.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   178
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   179
1205
79d33f7db590 [doc] some more small improvements
Emile Anclin <emile.anclin@logilab.fr>
parents: 1164
diff changeset
   180
Definition of relations
79d33f7db590 [doc] some more small improvements
Emile Anclin <emile.anclin@logilab.fr>
parents: 1164
diff changeset
   181
-----------------------
122
ac5ea13f8945 merged into the security definition section
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 101
diff changeset
   182
ac5ea13f8945 merged into the security definition section
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 101
diff changeset
   183
XXX add note about defining relation type / definition
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   184
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   185
A relation is defined by a Python class heriting `RelationType`. The name
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   186
of the class corresponds to the name of the type. The class then contains
1641
2c80b09d8d86 backport default
sylvain.thenault@logilab.fr
parents: 1477 1598
diff changeset
   187
a description of the properties of this type of relation, and could as well
1163
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
   188
contain a string for the subject and a string for the object. This allows to create
1641
2c80b09d8d86 backport default
sylvain.thenault@logilab.fr
parents: 1477 1598
diff changeset
   189
new definition of associated relations, (so that the class can have the
229
767ff7f5d5a7 [doc] Replace all : s/by example/for example/
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 171
diff changeset
   190
definition properties from the relation) for example ::
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   191
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   192
  class locked_by(RelationType):
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   193
    """relation on all entities indicating that they are locked"""
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   194
    inlined = True
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   195
    cardinality = '?*'
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   196
    subject = '*'
1398
5fe84a5f7035 rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents: 1222
diff changeset
   197
    object = 'CWUser'
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   198
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   199
In addition to the permissions, the properties of the relation types
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   200
(shared also by all definition of relation of this type) are :
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   201
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   202
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   203
* `inlined` : boolean handling the physical optimization for archiving
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   204
  the relation in the subject entity table, instead of creating a specific
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   205
  table for the relation. This applies to the relation when the cardinality
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   206
  of subject->relation->object is 0..1 (`?`) or 1..1 (`1`)
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   207
1163
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
   208
* `symmetric` : boolean indicating that the relation is symmetrical, which
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   209
  means `X relation Y` implies `Y relation X`
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   210
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   211
In the case of simultaneous relations definitions, `subject` and `object`
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   212
can both be equal to the value of the first argument of `SubjectRelation`
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   213
and `ObjectRelation`.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   214
1163
232aef110a0a doc improvements; typos
Emile Anclin <emile.anclin@logilab.fr>
parents: 1159
diff changeset
   215
When a relation is not inlined and not symmetrical, and it does not require
101
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   216
specific permissions, its definition (by using `SubjectRelation` and
c9138325b89f [doc] Initial translation for data model chapter.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 93
diff changeset
   217
`ObjectRelation`) is all we need.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   218
122
ac5ea13f8945 merged into the security definition section
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 101
diff changeset
   219
171
c7d6a465b951 updates done to documentation after following instructions for a new cube
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 128
diff changeset
   220
Updating your application with your new schema
1585
b86448eaed66 [doc] reduce the depth of the table of contents to get latex generation working
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1222
diff changeset
   221
----------------------------------------------
171
c7d6a465b951 updates done to documentation after following instructions for a new cube
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 128
diff changeset
   222
1641
2c80b09d8d86 backport default
sylvain.thenault@logilab.fr
parents: 1477 1598
diff changeset
   223
If you modified your schema, the update is not automatic; indeed, this is
1205
79d33f7db590 [doc] some more small improvements
Emile Anclin <emile.anclin@logilab.fr>
parents: 1164
diff changeset
   224
in general not a good idea.
1641
2c80b09d8d86 backport default
sylvain.thenault@logilab.fr
parents: 1477 1598
diff changeset
   225
Instead, you call a shell on your application, which is a
1164
88834894d2d7 explain cubicweb-ctl shell
Emile Anclin <emile.anclin@logilab.fr>
parents: 1163
diff changeset
   226
an interactive python shell, with an appropriate
88834894d2d7 explain cubicweb-ctl shell
Emile Anclin <emile.anclin@logilab.fr>
parents: 1163
diff changeset
   227
cubicweb environment ::
171
c7d6a465b951 updates done to documentation after following instructions for a new cube
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 128
diff changeset
   228
1159
16a426d214ae use english example names
Emile Anclin <emile.anclin@logilab.fr>
parents: 301
diff changeset
   229
   cubicweb-ctl shell myinstance
171
c7d6a465b951 updates done to documentation after following instructions for a new cube
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 128
diff changeset
   230
c7d6a465b951 updates done to documentation after following instructions for a new cube
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 128
diff changeset
   231
and type ::
c7d6a465b951 updates done to documentation after following instructions for a new cube
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 128
diff changeset
   232
1159
16a426d214ae use english example names
Emile Anclin <emile.anclin@logilab.fr>
parents: 301
diff changeset
   233
   add_entity_type('Person')
171
c7d6a465b951 updates done to documentation after following instructions for a new cube
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 128
diff changeset
   234
c7d6a465b951 updates done to documentation after following instructions for a new cube
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 128
diff changeset
   235
And restart your application!