tags:

views:

545

answers:

2

'alias' and 'name' are both properties in cake models. They seem to be similar, but since both of them exist, there must be a difference. What is it?

+1  A: 

I'm guessing, but an alias could be the assigned value when you have a relationship between a model and another and you give the associated model a name not equal to that of the class.

For example:

$hasMany = array('UserNew' => array('className' => 'User'));

In that case, you're using the model that's actually called User, but you're referencing it as 'UserNew'.

MSR
$hasMany = array('Friend' => array('className' => 'User')); would have be a better example, but you are correct. :)Because of this, you want to use `alias` where possible, since you can never be sure that `name` is actually the object you think you are dealing with.
deizel
A: 

It's a collection of table aliases used when cake does a join. From cake/lib/model/model_php5.php:

/**
 * Alias table names for model, for use in SQL JOIN statements.
 *
 * @var array
 * @access public
 */
    var $alias = array();
inkedmn