Wednesday, September 24, 2014

CakePHP automagic ID lookup for various data

Hello!

So this is really more of a general question, I'm hoping one day Google might pick it up for other Cake noobs like myself.

I'm sure I am missing something really simple here:
CakePHP cake bake all generates some scaffolding / CRUD views which work really well.

The behaviour I'm finding hard to replicate at the moment is when Cake automagically looks up the 'name' field for a given 'ID' if there is a connection.

So right now I'm outputting a table that has some data like this:
Row ID, Price, Price2, RepairName

And data for that looks a bit like:
Row ID, Price, Price2, RepairName
1,   21.00,    10.00,    1
1,    23.00,    09.00,    21
1,    21.20,    2.00,    998

So there we have it - Cake spitting out the 'ID' on the RepairName field instead of an actual value.

From my background I've a few different ways I can 'solve' this (those ideas including pulling an array of data for me to then do a manual 'lookup' for each row we output) - but all of these ideas seem hacky when I am sure (and I have seen with the basic CRUD views) the auto magic behaviour doing this work for me.

So perhaps this is down to model associations, in which case can you explain, in real simple terms how I should solve my ID lookup issue?

I've many models inter connecting which I've tried to not alter too much (as Cake generated them for me).

I was thinking there must be something really obvious here because surely this sort of question would come up more often? Weird how Google comes up short for me (Perhaps I don't know the proper phraseology!) 

Cheers then
Paul 

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

No comments: