Answer the question
In order to leave comments, you need to log in
How to execute AR Query in Yii to select records by value of related data?
Good afternoon,
There are 2 tables:
m_bids
------------
id
mc_points
------------
id
bid_id
time_start(int)
time_finish(int)
is_tart(bool)
For one entries in m_bids can only be 2 entries in mc_points . The first entry in mc_points is the starting point ( is_start(true) ) , the second point is the finish.
time_start and time_finish are defined for the start point - start range.
We need to get all m_bids whose time_finish at the start point is greater than the current time (we don't care about the end point, because time_startand time_finish are empty). Something like :
SELECT * FROM m_bids LEFT JOIN mc_points ON m_bids.id = mc_points.bid_id WHERE mc_pointsюtime_finish is not NULL AND mc_points.time_finish < 'x';
'points' => [self::HAS_MANY, 'Points', 'bid_id'],
$criteria = new CDbCriteria();
$criteria->join = 'LEFT JOIN mc_points ON `m_bids`.`id` = mc_points.bid_id';
$criteria->condition = 'mc_points time_finish IS NOT NULL AND time_finish < '.time();
$model = Bids::model()->published()->getAll($criteria);
Answer the question
In order to leave comments, you need to log in
SELECT * FROM m_bids LEFT JOIN mc_points ON m_bids.id = mc_points.bid_id WHERE mc_points.time_finish is not NULL AND mc_points.time_finish > CURDATE();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question