Friday, January 2, 2009

Re: multiple belongsTo and "related"

To fix this, all you need to do is add a 'displayField' to your
model.

I use this on my models to allow me to show a list of names on the
Cake generated forms and it works swimmingly. For instance in my User
model, I have the following:

var $displayField = 'full_name';

Then on forms where I want to pick a user, it displays the value from
the full_name field, and the selection passes the ID value in.

Note that as I understand it, Cake will do it's best to figure out
what the display field is before reverting to the ID value for
display. So if you have a field called 'name' it will display that
instead of the ID.

On Dec 28 2008, 4:37 pm, PaulSantus <paul.san...@gmail.com> wrote:
> Hi,
>
> I'm still quite new at CakePHP so it may be why I didn't get that.
> Here is my problem:
> I've got three Models: books, writers, publishers. All have only id
> and name fields, to make it simple.
>
> 1. Correct me if I'm wrong, but relationships should be as follow:
> Book belongsTo Writer
> Book belongsTo Publisher
> Writer hasMany Book
> Publisher hasMany Book
>
> 2. I'm really happy with what Bake cooked for me. Except in one case.
> When I'm using the view action of the Writer controller, at the bottom
> there is a very convenient table, showing related Books. But this
> tables doesn't show the Publisher 'name' but its 'id'. I'd like to see
> the 'name' here instead of the id.
> That is, I'd like CakePHP to make a JOIN query in the "Related" area
> of the writer/view action.
>
> 3. Here is what I've tried
> - modifying the relationships between the models.
> - playing with the $recursive parameter of the model.
> - playing with the fields parameter of the belongsTo relationship or
> the hasMany relationship.
>
> None of these above worked. Would you be compassionate enough to help
> me find a solution? This way, I'd definitively get better at
> baking..!
>
> Thanks a lot,
> Paul
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: