Re: Setting arrays for a complicated HABTM relationship

2010-03-23 Thread WebbedIT
Working with and quickly understanding utility libraries early on is a
sign that you should do ok.  And we're always here to help if we can!

Paul

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: Setting arrays for a complicated HABTM relationship

2010-03-22 Thread Shantam Jason Galuten
Yes, thanks so much. I still feel like there could be more complicated
things that I wouldn't know how to do, but I'll cross that bridge when I get
to it   ;)


On Mon, Mar 22, 2010 at 1:21 AM, WebbedIT  wrote:

> Glad I set you on the right path, Set::combine is a handy and powerful
> tool when playing with arrays :P
>
> Paul
>
> Check out the new CakePHP Questions site http://cakeqs.org and help others
> with their CakePHP related questions.
>
> 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+unsubscr...@googlegroups.comFor
>  more options, visit this group at
> http://groups.google.com/group/cake-php?hl=en
>
> To unsubscribe from this group, send email to cake-php+
> unsubscribegooglegroups.com or reply to this email with the words "REMOVE
> ME" as the subject.
>

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: Setting arrays for a complicated HABTM relationship

2010-03-22 Thread WebbedIT
Glad I set you on the right path, Set::combine is a handy and powerful
tool when playing with arrays :P

Paul

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: Setting arrays for a complicated HABTM relationship

2010-03-21 Thread paws_galuten
Ha! I figured it out... I can just change this:

$this->set('moods',
Set::combine($moods,'{n}.Moods.woman_id','{n}.Moods.mood','{n}.Moods.time_i
d'));

to this:

$this->set('moods',
Set::combine($moods,'{n}.Moods.woman_id','{n}.Moods','{n}.Moods.time_i
d'));


By changing '{n}.Moods.mood' to just '{n}.Moods' I get the whole array
instead of just the moods field.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: Setting arrays for a complicated HABTM relationship

2010-03-21 Thread paws_galuten
Thanks for the help.
Yes, Set::combine did the trick for me, but there's a complication
that leads me to another question. I did:

$moods = $this->Moods->find('all');
$this->set('moods',
Set::combine($moods,'{n}.Moods.woman_id','{n}.Moods.mood','{n}.Moods.time_id'));

That way in the view, I get an array that is grouped by the times, and
then lists the women's moods.

Like this:

Array
(
[1] => Array
(
[1] => Happy   <--- time 1, woman 1
[2] => Annoyed   <--- time 1, woman 2
[3] => Indifferent   etc.
 )

[2] => Array
(
[1] => Angry
[2] => Emotional
[3] => Silly
)
)

This works as long as there is only one attribute in the "moods" table
that I want to fetch. The question is... Let's say I have more that
one attribute in the moods table. Instead of just "mood", say it was
"inner_feeling" and "displayed_mood" for example. How, using
Set::combine (or some other way), can I get each of those moods to be
an array?

I'd like the data to look like this:

Array
(
[1] => Array
(
[1] => Array
(
[inner_feelings] => Happy
[displayed_mood] => Calm
)
[2] => Array
(
[inner_feelings] => Annoyed
[displayed_mood] => Tolerant
)
[3] => Array
(
[inner_feelings] => Indifferent
[displayed_mood] => Supportive
)
 )

[2] => Array
(
 etc...
)
)

Any ideas? Thanks so much...

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: Setting arrays for a complicated HABTM relationship

2010-03-21 Thread WebbedIT
P.S. defining the hasMany, belongsTo relationship rather than a HABTM
was the right decision.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: Setting arrays for a complicated HABTM relationship

2010-03-21 Thread WebbedIT
What have you tried so far?  I would say you could do this using GROUP
BY and/or Set::combine to structure your data array as required.

But I do not have this relationship setup anywhere with data so much
better if you show us what you have tried as that gives us something
to work with.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Setting arrays for a complicated HABTM relationship

2010-03-20 Thread paws_galuten
Hello experts!

Let's say there are many women in my life (ha!) and depending upon the
time, they might have different moods. This cannot be a simple HABTM
relationship because I want a value associated with the join table, so
I have defined the models like this:

Woman hasMany Mood
Time hasMany Mood
Mood belongsTo Woman, Time

The db would be something like:

Women {id, name}
Times {id, name}
Moods {id, woman_id, time_id, mood}  <--- by the way, is "mood" an ok
field name in the "moods" table, or should it be "name"?

Good so far?

Now, let's say in my view I just want to draw a table with Women
across the top (wife, daughter, etc...) and Times along the left side
(Morning, Afternoon, When I Forget A Birthday, etc...). Ideally I'd
want to just cycle through the times (creating table rows), and then
within each row, get each woman's mood for that time. Of course, the
first row will be the names of the women, and the first  of each
row will be the time.

It seems like a simple (and probably common) relationship, but I'm
having trouble seeing the clean and efficient way to set that array in
the controller.

Your thoughts are much appreciated!
Thanks,
Jason

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.