CakePHP manual 中文翻译

互联网 2006年12月14日 13:36 查看48923次 作者: helloliuchen  【
文章分类:PHP5研究[新]
接上页:

 

var $hasOne              = array('association1' =>
                       array('className'    => 'class',
                             'conditions'   => 'these conditions',
                             'order'        => 'this order by',
                             'dependent'    =>  true,
                             'foreignKey'   => 'foreign key'),
                                    
                             'association2' =>
                       array('className'    => 'class',
                             'conditions'   => 'these conditions',
                             'order'        => 'this order by',
                             'dependent'    =>  true,
                             'foreignKey'   => 'foreign key'),
                                    
                             'association3' =>
                       array('className'    => 'class',
                             'conditions'   => 'these conditions',
                             'order'        => 'this order by',
                             'dependent'    =>  true,
                             'foreignKey'   => 'foreign key'));
                                           
                                    
/**
* @var mixed $hasMany this can be a string or an array.
*
* Example below is using an array and setting more than one hasMany.
*
* Using hasMany as an array gives you more control over the association
*
* association - Table holding the association
* className   - Specify the class name of the association.
*                  Use it only if that name can not be inferred from the association
                   name.
*                     So
*                       [code]
*                         var $hasMany = array(array('products'));
*                       [/code]
*                  will by default be linked to the Product class, but if the real
                   class name is SpecialProduct, you'll have to specify it with this
                   option.
* conditions  - Specify the conditions that the associated objects must meet in order
                 to be included as a "WHERE" sql fragment, such as "price > 5 AND
                 name LIKE 'B%'".
* order       - Specify the order in which the associated objects are returned as a
                  "ORDER BY" sql fragment, such as "last_name, first_name DESC"
* foreignKey  - Specify the foreign key used for the association.
*                 By default this is guessed to be the name of this class in
                  lower-case and "_id" suffixed. So a Person class that makes a
                  has_many association will use "person_id" as the default
                  foreign_key.
* dependent   - If set to true all the associated object are destroyed alongside
                  this object. May not be set if exclusive is also set.
* exclusive   - If set to true all the associated object are deleted in one SQL
                  statement without having their beforeBestroy callback run. This
                  should only be used on associations that depend solely on this
                  class and don not need to do any clean-up in beforeDestroy. The
                  upside is that it's much faster, especially if there's a
                  counterCache involved. May not be set if dependent is also set.
* finderSql   - Specify a complete SQL statement to fetch the association.
*                 This is a good way to go for complex associations that depends
                  on multiple tables. Note: When this option is used,
                  findInCollection is not used.
* counterSql  - Specify a complete SQL statement to fetch the size of the association.
*                 If finderSql is specified but counterSql, counterSql will be
                  generated by replacing SELECT * FROM with SELECT COUNT(*) FROM.
*
*
* Setting $hasMany to a sting limits you alot.
* To use $hasMany as a string like this:
* [code]
* var $hasMany  = 'association';
* [/code]
*
* You can also set more than one association in the string by seperating them with a comma
* [code]
* var $hasMany = 'association,association2,association3';
* [/code]
*/                                    
var $hasMany             = array('association1' =>
                       array('className'    => 'class',
                             'conditions'   => 'these conditions',
                             'order'        => 'order by',
                             'foreignKey'   => 'foreign key',
                             'dependent'    =>  true,
                             'exclusive'    =>  false,
                             'finderSql'    => 'custom SQL',
                             'counterSql'   => 'custom SQL'),
                                   
                             'association2' =>
                       array('className'    => 'class',
                             'conditions'   => 'these conditions',
                             'order'        => 'order by',
                             'foreignKey'   => 'foreign key',
                             'dependent'    =>  false,
 
                             'exclusive'    =>  true,
                             'finderSql'    => 'custom SQL',
                             'counterSql'   => 'custom SQL'),
                                      
                             'association3' =>
                       array('className'    => 'class',
                             'conditions'   => 'these conditions',
                             'order'        => 'order by',
                             'foreignKey'   => 'foreign key',
                             'dependent'    =>  true,
                             'exclusive'    =>  false,
                             'finderSql'    => 'custom SQL',
                             'counterSql'   => 'custom SQL'));                                
                                    
/**
* @var mixed $hasAndBelongsToMany this can be a string or an array.
*
* Example below is using an array and setting more than one hasAndBelongsToMany.
*
* Using hasAndBelongsToMany as an array gives you more control over the association
*
* association - Table holding the association
* className - Specify the class name of the association.
*                Use it only if that name can not be inferred from the association
                 name.
*                   So
*                       [code]
*                         var $hasAndBelongsToMany = array(array('projects'));
*                       [/code]
*                    will by default be linked to the Project class, but if the real
                     class name is SuperProject, you will have to specify it with
                     this option.
* joinTable - Specify the name of the join table if the default based on lexical
                order is not what you want. WARNING: If you're overwriting the table
                name of either class, the tableName method MUST be declared
                underneath any hasAndBelongsToMany declaration in order to work.
* foreignKey - Specify the foreign key used for the association.
*                By default this is guessed to be the name of this class in
                 lower-case and "_id" suffixed. So a Person class that makes a
                 has_and_belongs_to_many association will use "person_id" as the
                 default foreign_key.
* associationForeignKey - Specify the association foreign key used for the
                 association. By default this is guessed to be the name of the
                 associated class in lower-case and "_id" suffixed. So the associated
                 class is Project that makes a hasAndBelongsToMany association will
                 use "project_id" as the default association foreignKey.
* conditions - Specify the conditions that the associated object must meet in order
                 to be included as a "WHERE" SQL fragment, such as "authorized = 1".
* order - Specify the order in which the associated objects are returned as an "ORDER
                 BY" SQL fragment, such as "last_name, first_name DESC"
* uniq - If set to true, duplicate associated objects will be ignored by accessors
                 and query methods
* finderSql - Overwrite the default generated SQL used to fetch the association
                 with a custom one
* deleteSql - Overwrite the default generated SQL used to remove links between the
                 associated classes with a custom one
* insertSql - Overwrite the default generated SQL used to add links between the
                 associated classes with a custom one
*
*
* Setting $hasAndBelongsToMany to a string limits you a lot.
* To use $hasAndBelongsToMany as a string like this:
* [code]
* var $hasAndBelongsToMany  = 'Association';
* [/code]
*
* You can also set more than one association, by separating them with a comma:
* [code]
* var $hasAndBelongsToMany = 'Association,Association2,Association3';
* [/code]
*/                        
var $hasAndBelongsToMany = array('Association1'          =>
                       array('className'             => 'ClassNameInCamelCase',
                             'joinTable'             => 'table to join on',
                             'foreignKey'            => 'foreign key',
                             'associationForeignKey' => 'foreign key',
                             'conditions'            => 'these conditions',
                             'order'                 => 'ORDER BY',
                             'uniq'                  =>  true,
责任编辑:抽烟的蚊子

给文章打分...

平均分:0.3(75 次)

-5 -4 -3 -2 -1 0 1 2 3 4 5
12

顶一下

发表我的见解...

  • 您的大名: 留空为匿名
  • 您的主页:
  • 您的邮箱: