Created
April 29, 2014 22:39
-
-
Save angelxmoreno/0939f976a8827dba753b to your computer and use it in GitHub Desktop.
Advance use of CakePHP Virtual Fields
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Constructor. Binds the model's database table to the object. | |
* | |
* @param integer|string|array $id Set this ID for this model on startup, can also be an array of options, see above. | |
* @param string $table Name of database table to use. | |
* @param string $ds DataSource connection name. | |
*/ | |
public function __construct($id = false, $table = null, $ds = null) { | |
parent::__construct($id, $table, $ds); | |
//verify that all children have a $role | |
$this->virtualFields['name'] = sprintf('CONCAT(%s.first_name, " ", %s.last_name)', $this->alias, $this->alias); | |
$this->virtualFields['initials'] = sprintf('CONCAT(UPPER(LEFT(%s.first_name,1)), UPPER(LEFT(%s.last_name,1)))', $this->alias, $this->alias); | |
$this->virtualFields['last_schoolclass_visited'] = sprintf('(SELECT `user_settings`.`last_class_visited` FROM `user_settings` where `user_settings`.`user_id` = `%s`.`id`)', $this->alias); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment