I have a db modelled like this:
User
+ id
+ email
+ password
Profile
+ id
+ owner_id (FK user.id)
+ type_id (FK types.id)
+ address_id (FK addresses.id)
+ org_name
+ phone
+ email
+ url
etc
Postings
+ id
+ profile_id (FK profiles.id)
+ title
+ description
Addresses
+ id
+ street
+ city
+ province_id (FK provinces.id)
+ country_id (FK countries.id)
etc
Countries
+ id
+ name
Provinces
+ id
+ name
+ abbreviation
+ country_id
I am trying to use Eloquent ORM to query a set of Postings from this based upon type_id, city, country_id and/or province_id. These fields are on the subordinate object $posting->profile->address, etc.
Am I going to have to dumb-down my db - flatten out the profile by merging the address data into it? Or is there a way to do this in Eloquent without remodelling all my data?
This is how you filter the table based on constraints in related tables:
It will set 2 joins and check those
where
clauses, so you will fetch only those posts, that meet the requirements, but nothing is eager loaded here (with
is for eager loading, but it doesn't filter the main model, only those eager loaded).Assuming you have defined a relationship of
address
forprofile
,