CakePHP manual 中文翻译5

接上页:

  1. var $hasOne              = array('association1' =>
  2.                        array('className'    => 'class',
  3.                              'conditions'   => 'these conditions',
  4.                              'order'        => 'this order by',
  5.                              'dependent'    =>  true,
  6.                              'foreignKey'   => 'foreign key'),
  7.                                    
  8.                              'association2' =>
  9.                        array('className'    => 'class',
  10.                              'conditions'   => 'these conditions',
  11.                              'order'        => 'this order by',
  12.                              'dependent'    =>  true,
  13.                              'foreignKey'   => 'foreign key'),
  14.                                    
  15.                              'association3' =>
  16.                        array('className'    => 'class',
  17.                              'conditions'   => 'these conditions',
  18.                              'order'        => 'this order by',
  19.                              'dependent'    =>  true,
  20.                              'foreignKey'   => 'foreign key'));
  21. <span id="more-21"></span>                                        
  22. /**
  23. * @var mixed $hasMany this can be a string or an array.
  24. *
  25. * Example below is using an array and setting more than one hasMany.
  26. *
  27. * Using hasMany as an array gives you more control over the association
  28. *
  29. * association - Table holding the association
  30. * className   - Specify the class name of the association.
  31. *                  Use it only if that name can not be inferred from the association
  32.                    name.
  33. *                     So
  34. *                       [code]
  35. *                         var $hasMany = array(array('products'));
  36. *                       [/code]
  37. *                  will by default be linked to the Product class, but if the real
  38.                    class name is SpecialProduct, you'll have to specify it with this
  39.                    option.
  40. * conditions  - Specify the conditions that the associated objects must meet in order
  41.                  to be included as a "WHERE" sql fragment, such as "price > 5 AND
  42.                  name LIKE 'B%'".
  43. * order       - Specify the order in which the associated objects are returned as a
  44.                   "ORDER BY" sql fragment, such as "last_name, first_name DESC"
  45. * foreignKey  - Specify the foreign key used for the association.
  46. *                 By default this is guessed to be the name of this class in
  47.                   lower-case and "_id" suffixed. So a Person class that makes a
  48.                   has_many association will use "person_id" as the default
  49.                   foreign_key.
  50. * dependent   - If set to true all the associated object are destroyed alongside
  51.                   this object. May not be set if exclusive is also set.
  52. * exclusive   - If set to true all the associated object are deleted in one SQL
  53.                   statement without having their beforeBestroy callback run. This
  54.                   should only be used on associations that depend solely on this
  55.                   class and don not need to do any clean-up in beforeDestroy. The
  56.                   upside is that it's much faster, especially if there's a
  57.                   counterCache involved. May not be set if dependent is also set.
  58. * finderSql   - Specify a complete SQL statement to fetch the association.
  59. *                 This is a good way to go for complex associations that depends
  60.                   on multiple tables. Note: When this option is used,
  61.                   findInCollection is not used.
  62. * counterSql  - Specify a complete SQL statement to fetch the size of the association.
  63. *                 If finderSql is specified but counterSql, counterSql will be
  64.                   generated by replacing SELECT * FROM with SELECT COUNT(*) FROM.
  65. *
  66. *
  67. * Setting $hasMany to a sting limits you alot.
  68. * To use $hasMany as a string like this:
  69. * [code]
  70. * var $hasMany  = 'association';
  71. * [/code]
  72. *
  73. * You can also set more than one association in the string by seperating them with a comma
  74. * [code]
  75. * var $hasMany = 'association,association2,association3';
  76. * [/code]
  77. */                                   
  78. var $hasMany             = array('association1' =>
  79.                        array('className'    => 'class',
  80.                              'conditions'   => 'these conditions',
  81.                              'order'        => 'order by',
  82.                              'foreignKey'   => 'foreign key',
  83.                              'dependent'    =>  true,
  84.                              'exclusive'    =>  false,
  85.                              'finderSql'    => 'custom SQL',
  86.                              'counterSql'   => 'custom SQL'),
  87.                                   
  88.                              'association2' =>
  89.                        array('className'    => 'class',
  90.                              'conditions'   => 'these conditions',
  91.                              'order'        => 'order by',
  92.                              'foreignKey'   => 'foreign key',
  93.                              'dependent'    =>  false,
  94.  
  95.                              'exclusive'    =>  true,
  96.                              'finderSql'    => 'custom SQL',
  97.                              'counterSql'   => 'custom SQL'),
  98.                                      
  99.                              'association3' =>
  100.                        array('className'    => 'class',
  101.                              'conditions'   => 'these conditions',
  102.                              'order'        => 'order by',
  103.                              'foreignKey'   => 'foreign key',
  104.                              'dependent'    =>  true,
  105.                              'exclusive'    =>  false,
  106.                              'finderSql'    => 'custom SQL',
  107.                              'counterSql'   => 'custom SQL'));                               
  108.                                    
  109. /**
  110. * @var mixed $hasAndBelongsToMany this can be a string or an array.
  111. *
  112. * Example below is using an array and setting more than one hasAndBelongsToMany.
  113. *
  114. * Using hasAndBelongsToMany as an array gives you more control over the association
  115. *
  116. * association - Table holding the association
  117. * className - Specify the class name of the association.
  118. *                Use it only if that name can not be inferred from the association
  119.                  name.
  120. *                   So
  121. *                       [code]
  122. *                         var $hasAndBelongsToMany = array(array('projects'));
  123. *                       [/code]
  124. *                    will by default be linked to the Project class, but if the real
  125.                      class name is SuperProject, you will have to specify it with
  126.                      this option.
  127. * joinTable - Specify the name of the join table if the default based on lexical
  128.                 order is not what you want. WARNING: If you're overwriting the table
  129.                 name of either class, the tableName method MUST be declared
  130.                 underneath any hasAndBelongsToMany declaration in order to work.
  131. * foreignKey - Specify the foreign key used for the association.
  132. *                By default this is guessed to be the name of this class in
  133.                  lower-case and "_id" suffixed. So a Person class that makes a
  134.                  has_and_belongs_to_many association will use "person_id" as the
  135.                  default foreign_key.
  136. * associationForeignKey - Specify the association foreign key used for the
  137.                  association. By default this is guessed to be the name of the
  138.                  associated class in lower-case and "_id" suffixed. So the associated
  139.                  class is Project that makes a hasAndBelongsToMany association will
  140.                  use "project_id" as the default association foreignKey.
  141. * conditions - Specify the conditions that the associated object must meet in order
  142.                  to be included as a "WHERE" SQL fragment, such as "authorized = 1".
  143. * order - Specify the order in which the associated objects are returned as an "ORDER
  144.                  BY" SQL fragment, such as "last_name, first_name DESC"
  145. * uniq - If set to true, duplicate associated objects will be ignored by accessors
  146.                  and query methods
  147. * finderSql - Overwrite the default generated SQL used to fetch the association
  148.                  with a custom one
  149. * deleteSql - Overwrite the default generated SQL used to remove links between the
  150.                  associated classes with a custom one
  151. * insertSql - Overwrite the default generated SQL used to add links between the
  152.                  associated classes with a custom one
  153. *
  154. *
  155. * Setting $hasAndBelongsToMany to a string limits you a lot.
  156. * To use $hasAndBelongsToMany as a string like this:
  157. * [code]
  158. * var $hasAndBelongsToMany  = 'Association';
  159. * [/code]
  160. *
  161. * You can also set more than one association, by separating them with a comma:
  162. * [code]
  163. * var $hasAndBelongsToMany = 'Association,Association2,Association3';
  164. * [/code]
  165. */                       
  166. var $hasAndBelongsToMany = array('Association1'          =>
  167.                        array('className'             => 'ClassNameInCamelCase',
  168.                              'joinTable'             => 'table to join on',
  169.                              'foreignKey'            => 'foreign key',
  170.                              'associationForeignKey' => 'foreign key',
  171.                              'conditions'            => 'these conditions',
  172.                              'order'                 => 'ORDER BY',
  173.                              'uniq'                  =>  true,
  174. ?>
Trackback url : u can trackback from your own site
posted @ 2008-11-10 10:28  酷越  阅读(359)  评论(0编辑  收藏  举报