M
M
Melodic2014-08-28 17:34:15
MySQL
Melodic, 2014-08-28 17:34:15

How to put two different models in one DataProvider in Yii?

There are two models: Place (Cafe, restaurant, cinema) and Event.
The event has its own date.
The place has a work schedule (Mon, Tue, Wed, etc.).
It is necessary to select everything somehow (for example, for the date 08/28/2014) in the amount of 10 pieces sorted by id. And this should include events held on 08/28/2014 and places that are open on Thursday (because 08/28/2014 is Thursday).
What are the solutions?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2014-08-28
Protko @Fesor

You do not need to have several models in one data provider, you need to understand the object relationships and build them correctly.
Something like this.

$dataProvider = Event::getEventsForDate(new \DateTime('28.08.2014'));
foreach ($dataProvider->getData() as $event) {
    $venue = $event->venue;
}

A
Alexander Zelenin, 2014-08-29
@zelenin

@Melodic your Event should have a venue_id field with a getVenue() (one-to-one) relationship to the Venue table. This way you will access the place via $event->venue

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question