-
-
Save obinoob/43ab432873ea04fb171cba437c4b6e5a to your computer and use it in GitHub Desktop.
This file contains 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 | |
// Posts hasMany Images | |
// Posts hasOne FeaturedImages: where featured image is the first image for that post. | |
$this->hasOne('FeaturedImages', [ | |
'className' => 'Images', | |
'foreignKey' => false, | |
'conditions' => function ($exp, $query) { | |
$subquery = $query | |
->connection() | |
->newQuery() | |
->select(['SubFeaturedImages.id']) | |
->from(['SubFeaturedImages' => 'images']) | |
->where(['SubFeaturedImages.post_id = Posts.id']) | |
->order(['SubFeaturedImages.id' => 'ASC']) | |
->limit(1); | |
return $exp->add(['FeaturedImages.id' => $subquery]); | |
} | |
]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment