We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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.



5.7k
Accepted
answer

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