https://github.com/ADmad/cakephp-jwt-auth
Thursday, October 18, 2018
CakePhp Eluquent Subquery Example
public function beforeSave(Event $event, Entity $entity){
}
public function initialize(array $config)
{
$this->addBehavior('Timestamp'); //gestion des colonnes created et modified
$this->hasMany('ForumPosts');
$this->hasOne('LastForumPost', [
'className' => 'ForumPosts',
'foreignKey' => false,
'conditions' => function ($exp, $query) {
$subquery = $query
->getConnection()
->newQuery()
->select(['SubLastForumPost.id'])
->from(['SubLastForumPost' => 'forum_posts'])
->where([
'SubLastForumPost.draft = false', //to remove for admin
'SubLastForumPost.created IS NOT NULL',
'ForumCategories.id = SubLastForumPost.forum_category_id',
'SubLastForumPost.parent_id IS NULL'])
->order(['SubLastForumPost.created' => 'DESC'])
->limit(1);
return $exp->add(['LastForumPost.id' => $subquery]);
}
]);
}From cakephp forum
Subscribe to:
Posts (Atom)
-
Composer is a major part of the Laravel MVC Framework, but it also exists without Laravel. In fact you could use it in any project. This a...
-
How to Answer Technical Questions Like a Pro Answering technical interview questions is all about showing off your problem-solving skills an...
-
Vuetify is a popular UI framework for Vue apps. In this article, we’ll look at how to work with the Vuetify framework. Color Picker Inputs W...