doc/book/en/devrepo/datamodel/definition.rst
changeset 10093 516a44ae2cc9
parent 9990 c84ad981fc4a
child 10136 c33dcd18e0bb
equal deleted inserted replaced
10092:f0363da0b5a0 10093:516a44ae2cc9
    90 
    90 
    91 There is also a `RichString` kindof type:
    91 There is also a `RichString` kindof type:
    92 
    92 
    93  .. autoclass:: yams.buildobjs.RichString
    93  .. autoclass:: yams.buildobjs.RichString
    94 
    94 
       
    95 The ``__unique_together__`` class attribute is a list of tuples of names of
       
    96 attributes or inlined relations.  For each tuple, CubicWeb ensures the unicity
       
    97 of the combination.  For example:
       
    98 
       
    99 .. sourcecode:: python
       
   100 
       
   101   class State(EntityType):
       
   102       __unique_together__ = [('name', 'state_of')]
       
   103 
       
   104       name = String(required=True)
       
   105       state_of = SubjectRelation('Workflow', cardinality='1*',
       
   106                                  composite='object', inlined=True)
       
   107 
    95 
   108 
    96 You can find more base entity types in
   109 You can find more base entity types in
    97 :ref:`pre_defined_entity_types`.
   110 :ref:`pre_defined_entity_types`.
    98 
   111 
    99 .. XXX yams inheritance
   112 .. XXX yams inheritance
   271 
   284 
   272 * `RQLUniqueConstraint`: allows to the specify a RQL query that ensure that an
   285 * `RQLUniqueConstraint`: allows to the specify a RQL query that ensure that an
   273   attribute is unique in a specific context. The Query must **never** return more
   286   attribute is unique in a specific context. The Query must **never** return more
   274   than a single result to be satisfied. In this query the variables `S` is
   287   than a single result to be satisfied. In this query the variables `S` is
   275   reserved for the relation subject entity. The other variables should be
   288   reserved for the relation subject entity. The other variables should be
   276   specified with the second constructor argument (mainvars). This constraints
   289   specified with the second constructor argument (mainvars). This constraint type
   277   should be used when UniqueConstraint doesn't fit. Here is a simple example.
   290   should be used when __unique_together__ doesn't fit.
   278 
       
   279 .. sourcecode:: python
       
   280 
       
   281     # Check that in the same Workflow each state's name is unique.  Using
       
   282     # UniqueConstraint (or unique=True) here would prevent states in different
       
   283     # workflows to have the same name.
       
   284 
       
   285     # With: State S, Workflow W, String N ; S state_of W, S name N
       
   286 
       
   287     RQLUniqueConstraint('S name N, S state_of WF, Y state_of WF, Y name N',
       
   288                         mainvars='Y',
       
   289                         msg=_('workflow already has a state of that name'))
       
   290 
   291 
   291 .. XXX note about how to add new constraint
   292 .. XXX note about how to add new constraint
   292 
   293 
   293 .. _securitymodel:
   294 .. _securitymodel:
   294 
   295