Created
October 10, 2014 00:51
-
-
Save markstory/f7d37eebeab7474f1636 to your computer and use it in GitHub Desktop.
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
<?php | |
App::uses('AppModel', 'Model'); | |
/** | |
* Article Model | |
* | |
* @property Comment $Comment | |
*/ | |
class Article extends AppModel { | |
/** | |
* Validation rules | |
* | |
* @var array | |
*/ | |
public $validate = array( | |
'title' => array( | |
'notEmpty' => array( | |
'rule' => array('notEmpty'), | |
), | |
), | |
); | |
/** | |
* hasMany associations | |
* | |
* @var array | |
*/ | |
public $hasMany = array( | |
'Comment' => array( | |
'className' => 'Management.Comment', | |
'foreignKey' => 'article_id', | |
'dependent' => false, | |
'conditions' => '', | |
'fields' => '', | |
'order' => '', | |
'limit' => '', | |
'offset' => '', | |
'exclusive' => '', | |
'finderQuery' => '', | |
'counterQuery' => '' | |
) | |
); | |
} |
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
<?php | |
App::uses('AppController', 'Controller'); | |
/** | |
* Articles Controller | |
* | |
*/ | |
class ArticlesController extends AppController { | |
public function index() { | |
$this->autoRender = false; | |
$res = $this->Article->find('all', [ | |
'contain' => ['Comment'] | |
]); | |
debug($res); | |
debug($this->Article->getDataSource()->getLog()); | |
} | |
} |
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
<?php | |
/** | |
* In this file you set up your database connection details. | |
* | |
* @package cake | |
* @subpackage cake.config | |
*/ | |
class DATABASE_CONFIG { | |
// MySQL | |
var $default = array( | |
'datasource' => 'Database/Mysql', | |
'persistent' => false, | |
'host' => 'localhost', | |
'login' => 'root', | |
'password' => '', | |
'database' => 'cake_debug', | |
'prefix' => 'pre_', | |
'encoding' => 'utf8' | |
); | |
} |
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
CREATE TABLE `pre_articles` ( | |
`id` int(11) NOT NULL AUTO_INCREMENT, | |
`title` varchar(255) NOT NULL, | |
`body` text, | |
`created` datetime DEFAULT NULL, | |
`modified` datetime DEFAULT NULL, | |
PRIMARY KEY (`id`) | |
); | |
CREATE TABLE `pre_comments` ( | |
`id` int(11) NOT NULL AUTO_INCREMENT, | |
`article_id` int(11) NOT NULL, | |
`body` text, | |
`created` datetime DEFAULT NULL, | |
`modified` datetime DEFAULT NULL, | |
PRIMARY KEY (`id`) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment