Let's say I have a database table called article
, and each article is assigned a type
(1 = standard article, 2 = sponsored article, etc.).
Using Propel 2, is it possible to do the following?
Step 1: Select the 10 latest articles, ordered descending, of type = 1
(This is a no brainer).
$articles = ArticleQuery::create()
->filterByType(1)
->orderByPublishedAt('desc')
->limit(10)
->find();
Step 2: Select 2 random articles of type = 2
and randomly insert them into the current $articles
object. This is the step where I'm at a loss.
For example, the final resulting selection would look something like this:
- Standard Article
- Standard Article
- Random Sponsored Article (inserted here randomly)
- Standard Article
- Standard Article
- Random Sponsored Article (inserted here randomly)
- Standard Article
- Standard Article
- Standard Article
- Standard Article
- Standard Article
- Standard Article
It seems that I should be able to extend the ArticleQuery
class by writing some sort of insertRandomSponsoredArticles()
function, but I'm not quite sure how to go about this.