Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0
  1. Please follow laravel's innate db structure
  return $this->hasMany('City', 'district.CityID', 'city.CityID');   //this fails 

not sure if that would work, i use laravel's innate db structure so i wont have any issue like this

Last updated 2 years ago.
0

lightshire said:

  1. Please follow laravel's innate db structure
 return $this->hasMany('City', 'district.CityID', 'city.CityID');   //this fails 

not sure if that would work, i use laravel's innate db structure so i wont have any issue like this

Thank you for your reply, but it does not work. I have no clue why Country->District works, but District->City ... I already spent few days on it... and totally clueless.

Last updated 2 years ago.
0

Fix that relationship with DistrictID instead of CityID and it will work, no need to prefix table name, Eloquent will do that for you on this relation query.

Last updated 2 years ago.
0

jarektkaczyk said:

Fix that relationship with DistrictID instead of CityID and it will work, no need to prefix table name, Eloquent will do that for you on this relation query.

OMG - I feel so stupid now... I can't believe it - I spent few days on it... reloaded my database few times, added and dropped keys in database, and did all kinds of troubleshooting. In the end, I just tried to link to not existing Column - LOL.

Thank you very, very much jarektkaczyk!!!

LOL - in the end I just tried to link Mode

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.