Search code examples
phpmysqlsqlzend-frameworkpropel

Select data from 2 tables + propel


I have a table "parkinggarages" with a foreign key "location_id". I also have a table "locations".

Table parkinggarages:
- id
- phone
- defaultlanguage
- capacity
- floors
- parkingtype

Table locations:
- id
- location
- lat
- lon

Now I want to select all the parkinggarages but I also want to select the "location" field from table "locations" with it.

How can I do this? I've tried this, but didn't work:

$result = ParkinggarageQuery::create()->joinWith('Location.location')

Solution

  • $parkinggarages = ParkinggarageQuery::create()
                ->leftJoinWith('Parkinggarage.Location')
                ->find();