Answer the question
In order to leave comments, you need to log in
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
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;
}
@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 questionAsk a Question
731 491 924 answers to any question