Related associations in View


#1

Hey there,

I set up a small database for understanding how cakephp handles database tables associations, but currently Im kind of confused.
I have two tables, offers and addresses. There is a foreign key from offers to addresses (address_id). In my AddressesTable Cakephp created a hasMany association to offers. In my OffersTable I have a belongsTo association. When I open Offers/view there is an added column Address with the related Id. But instead of a Link to the related Id I’d like to see the related address.

So I added a foreach-Loop in my Offers/view, but still no address is displayed. The reason, why Im confused is, because when I turn the foreign Key the other way round, from address to offers, the address is displayed in my view.
So my question is, why Cakephp implements the association in the view only in “one directon” ?


#2

Can’t you just change the display field property to use address instead of id ?


#3

Im not sure.
But after my post here I did some try&error, for understanding und for seeing what I want in my view. Maybe I thought about it in the wrong way, but now it works :slight_smile: