Laravel 5.2 & Models with non-int keys

Yes, yes I’ve been neglecting my own site. Mustache treat & Roxie

Yes, I’ve been busy.

Yes, I’ve still been training.

Yes, Roxie keeps me busy and she is still alive and very well and energetic as hell. …she’s also still SUPER
adorable. In fact, here’s another picture to share BECAUSE I CAN.

I can’t help it if she’s hilarious and makes me laugh.

Anywho, at work, I’ve been SUPER busy with BIG (MASSIVE) projects. My current project is upgrading my Laravel 4.2 project to Laravel 5.2. Let me tell you, it’s been a PITA and BOY have I been crashing and burning but I’m learning lots. This post is about something that I learned recently thanks to a gentleman on StackOverflow. I has having a lot of issues with Laravel’s Eager Loading to not work all of a sudden. It would return null, but when I called the relationship manually, it was fine and worked. Turns out, if you’ve got models with a key that isn’t an integer, you need to add one more link to the model setup. The line is:

public $incrementing = false;

That’s it! After that, the model and eager loading worked just fine. I never saw anything in the documentation regarding this so I thought I’d post about it.

That’s your latest tip of the…several months? I’ve got others, but they would take longer to post. ^_^

Anywho, toodles!

Leave a Reply

Your email address will not be published. Required fields are marked *