Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Do model relationships only work with ids (numbers) ?

Hey,

I have an existing database that works with varchars(255) as foreign keys. When I try to build relations with "$this->belongsTo('publisher', 'Publisher', 'name');" and "$this->hasMany('name', 'Modpack', 'publisher');" I get a non object error when I use: {{ modpack.publisher.link }}. In other projects where the foreign keys are based on ints I never had an issues with it, which is makeing me wonder.



2.9k
Accepted
answer

Ohh wow. I only needed to writhe Publisher uppercase that it understands I want the relation and not the column..