Re: selecting extra info from related fields for an association

2008-03-26 Thread jaypee

For anyone who found themselves understanding what I needed, this is
what I came up with that delivered a result.

My issue was that I had a field for first_name and a field for
last_name of people who referred the contact I was entering and I
could not get the auto-cake-magic to render the complete name. To
display a drop down box that would include the id and join the two
name fields together, I added this to the controller:


$referrers = $this->Contact->find('all', array('fields' =>
array('id','first_name','last_name')), 0);
$referrers = Set::combine($referrers, '{n}.Contact.id', array('{0}
{1}','{n}.Contact.first_name','{n}.Contact.last_name'));

$this->set(compact('referrers'));

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: selecting extra info from related fields for an association

2008-03-10 Thread Adam Royle

I generally use bake to create my admin code, which is what I've
already explained to you. Maybe you should try doing that and see what
cake generates for you. Otherwise, you'll need to paste your code
somewhere so we can see what you're doing.

Cheers,
Adam

On Mar 10, 8:26 am, jaypee <[EMAIL PROTECTED]> wrote:
> Hi Adam,
>
> I have done both the find() (eg $referrers = 
> $this->User->Referrer->find('list', array('fields' =>
>
> array('id','first_name','last_name')));) and the $displayField.
>
> For this particular form relating to the user, i track their referral
> source and type (eg, Adam Royle, CakeConvention (both belongsTo)) and
> a relationship they have with any entities (director of SleekGeek,
> consultant to BondsAustralia (HABTM)). Using the $displayField (and
> even if i could get afterFind() to work), I dont know how to use it
> for each view (redeclare $displayField).
>
> Looking at my my view and index views, i am extracting all the data I
> need its just a matter of being able to display it in the add and edit
> views in the options for a drop down select.
>
> Not bagging the efforts of others, but the documentation is limited
> and all the examples I have found use some deprecated call, function
> etc..
>
> How would you code a drop down select box??
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: selecting extra info from related fields for an association

2008-03-09 Thread jaypee

Hi Adam,

I have done both the find() (eg $referrers = $this->User->Referrer-
>find('list', array('fields' =>
array('id','first_name','last_name')));) and the $displayField.

For this particular form relating to the user, i track their referral
source and type (eg, Adam Royle, CakeConvention (both belongsTo)) and
a relationship they have with any entities (director of SleekGeek,
consultant to BondsAustralia (HABTM)). Using the $displayField (and
even if i could get afterFind() to work), I dont know how to use it
for each view (redeclare $displayField).

Looking at my my view and index views, i am extracting all the data I
need its just a matter of being able to display it in the add and edit
views in the options for a drop down select.

Not bagging the efforts of others, but the documentation is limited
and all the examples I have found use some deprecated call, function
etc..

How would you code a drop down select box??
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: selecting extra info from related fields for an association

2008-03-06 Thread Adam Royle

generateList() has been replaced by find('list')

I know people have spoke previously of select inputs not showing
correctly, and often I think it is because they didn't have a field
"name" or "title" in their model. Customising the find('list') is one
way of doing it, alternatively you can also set var $displayField =
"mytitle"; in the model to fix this.

I've also seen this issue occur when people have not set their
recursive level high enough, but without seeing your code it's hard to
debug. My suggestion is still to look at what data you are getting
from find('list') and go from there.

Cheers,
Adam

On Mar 7, 12:36 pm, jaypee <[EMAIL PROTECTED]> wrote:
> I'm glad you saw it because I only looked at that 15 times or so. Oh
> well.
>
> Now off to find more on the list generating issues. I think
> generateList might be what is required.
>
> Thanks Adam.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: selecting extra info from related fields for an association

2008-03-06 Thread jaypee

I'm glad you saw it because I only looked at that 15 times or so. Oh
well.

Now off to find more on the list generating issues. I think
generateList might be what is required.

Thanks Adam.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: selecting extra info from related fields for an association

2008-03-06 Thread Adam Royle

Hi Joshua,

The generated SQL looks wrong to me. It should be something like this
(see `User`.`id` = `Referrer`.`referrer_id`):

SELECT `User`.`id`, `User`.`created_by`, `Referrer`.`id`,
`Referrer`.`created_by` FROM `users` AS `User` LEFT JOIN `users` AS
`Referrer` ON (`User`.`id` = `Referrer`.`referrer_id`) WHERE 1 = 1
LIMIT 20

Check your association foreignKey to make sure you've specified it
correctly.

In your add and edit views, the select should be filled correctly as
long as you are passing $referrers to your view. Check the $referrers
array to see what data is in there.

Cheers,
Adam


On Mar 7, 8:52 am, jaypee <[EMAIL PROTECTED]> wrote:
> Gday Adam,
>
> Done that. Referrer|name just brings up the users name.. not the
> referrers name. It seems as if the only record it returns is the users
> except when i look at the sql dump it is SELECT `User`.`id`,
> `User`.`created_by`, etc, `Referrer`.`id`, `Referrer`.`created_by`,
> etc, FROM `users` AS `User` LEFT JOIN `users` AS `Referrer` ON
> (`User`.`id` = `Referrer`.`id`) WHERE 1 = 1 LIMIT 20
>
> The two things I can't do that I would like to is display the names of
> the 'referrers' in the select lists that is in the edit and add views,
> and output their names in the view and index views.
>
> From going through the controller, I need more code in the view and
> index functions. I have tried different variations of find() but I am
> stabbing in the dark. I have yet to find some documentation to make
> sense to me (im guessing this because the add and edit have $referrers
> = $this->User->Referrer->find('list'); in their functions).
>
> Also, in the add and edit views, I am trying to figure out to add to
> the existing helper code so that the output would allow me to  id=>
> >input('referrer_id');"
>
> Thanks in advance,
>
> Joshua.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: selecting extra info from related fields for an association

2008-03-06 Thread jaypee

Gday Adam,

Done that. Referrer|name just brings up the users name.. not the
referrers name. It seems as if the only record it returns is the users
except when i look at the sql dump it is SELECT `User`.`id`,
`User`.`created_by`, etc, `Referrer`.`id`, `Referrer`.`created_by`,
etc, FROM `users` AS `User` LEFT JOIN `users` AS `Referrer` ON
(`User`.`id` = `Referrer`.`id`) WHERE 1 = 1 LIMIT 20

The two things I can't do that I would like to is display the names of
the 'referrers' in the select lists that is in the edit and add views,
and output their names in the view and index views.

>From going through the controller, I need more code in the view and
index functions. I have tried different variations of find() but I am
stabbing in the dark. I have yet to find some documentation to make
sense to me (im guessing this because the add and edit have $referrers
= $this->User->Referrer->find('list'); in their functions).

Also, in the add and edit views, I am trying to figure out to add to
the existing helper code so that the output would allow me to >input('referrer_id');"

Thanks in advance,

Joshua.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: selecting extra info from related fields for an association

2008-03-06 Thread Adam Royle

I'm guessing you've got something like:

users
-
id
name
referrer_id
...

Then simply setup a new association in your users model.


 array('className' => 'User',
'foreignKey' => 
'referrer_id',
'fields' => 
array('id','name'),
)
);

}
?>


Then in your view you would do something like:



Cheers,
Adam


On Mar 6, 4:33 pm, jaypee <[EMAIL PROTECTED]> wrote:
> I have a self-join (belongsTo) within a users table to track who
> referred who.
>
> I have managed to produce the code to associate the user to referrer,
> however, i was wondering how in the add and edit views i can display
> the user's name instead of their id (which is the foreignKey)?
>
> I have tried adding to the $form->input() but I am not sure if I
> should adding the code to fetch the names of the users (who are
> generated within the referrer field) along with their id, in the
> controller or the view file/s?
>
> Any ideas would be appreciated.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



selecting extra info from related fields for an association

2008-03-06 Thread jaypee

I have a self-join (belongsTo) within a users table to track who
referred who.

I have managed to produce the code to associate the user to referrer,
however, i was wondering how in the add and edit views i can display
the user's name instead of their id (which is the foreignKey)?

I have tried adding to the $form->input() but I am not sure if I
should adding the code to fetch the names of the users (who are
generated within the referrer field) along with their id, in the
controller or the view file/s?

Any ideas would be appreciated.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---