I'm not sure your code is working, due to the relations
belongsTo (the column is probably
category_id instead of
id), amd that you try to retrieve your relations as if it was an array instead of an object...
But if it's work, good for you. If not, please give us some comments (what you tried to achieve, which errors occur, ...)