Saturday, May 2, 2009

RE: Removing an item from a set using Set::Remove.

I have run into something similar where I wanted to remove, but first find
out why a Part of the array was even showing up.

I have the 2 debug statements in concession so I can see what data goes in
the save and what is actually saved
Line 225
debug($this->data);
Returns
Array
(
[System] => Array
(
[System] => Array
(
[0] => 3
[1] => 5
[2] => 6
[3] => 1
)

)

)
Line 226
debug($this->User->save($this->data[$model_table], true,
array_keys($this->User->$join_table->schema())));
Returns
Array
(
[User] => Array
(
[id] => 3
)

[System] => Array
(
[0] => 3
[1] => 5
[2] => 6
[3] => 1
[4] => 3
[5] => 5
[6] => 6
[7] => 1
)

)

SQL = UPDATE `users` SET `id` = 3 WHERE `users`.`id` = 3

Howwould I remove the

[User] => Array
(
[id] => 3
)

-----Original Message-----
From: brian [mailto:bally.zijn@gmail.com]
Sent: May-02-09 1:18 PM
To: cake-php@googlegroups.com
Subject: Re: Removing an item from a set using Set::Remove.


Wait--that's not right at all! I just looked more closely at what you had
there (it's still early here; 1st coffee). Set::remove() doesn't work like
that. Say you wanted to remove all of the 'name' parts from the input
array. You'd do:

$events = Set::remove($events, '{n}.Event.name');

Giving you something like:

Array
(
[0] => Array
(
[Event] => Array
(
[id] => 1
)

)

[1] => Array
(
[Event] => Array
(
[id] => 2
)
)

[2] => Array
(
[Event] => Array
(
[id] => 3
)

)

)

There's no 3rd param.

For your purposes, why don't you simply use the conditions to keep certain
rows from being selected at all? Either that, or re-think how you're storing
this data. Why do you need to remove this or other rows? Perhaps there's a
more elegant solution.

On Sat, May 2, 2009 at 11:39 AM, brian <bally.zijn@gmail.com> wrote:
> I've never used it myself but that looks correct. Maybe you left it
> out of your example but make sure to assign the return from remove()
> back to your var.
>
> $events = Set::remove($events, '{n}.Event.id' , 2);
>
> On Fri, May 1, 2009 at 11:28 AM, Krist van Besien
> <krist.vanbesien@gmail.com> wrote:
>>
>> Suppose I have the following set:
>>
>> Array
>> (
>>    [0] => Array
>>        (
>>            [Event] => Array
>>                (
>>                    [id] => 1
>>                    [name] => 1
>>                               )
>>
>>        )
>>
>>    [1] => Array
>>        (
>>            [Event] => Array
>>                (
>>                    [id] => 2
>>                    [name] => 2
>>                                  )
>>        )
>>
>>    [2] => Array
>>        (
>>            [Event] => Array
>>                (
>>                    [id] => 3
>>                    [name] => 3
>>                                  )
>>
>>        )
>>
>> )
>>
>> ( This set was generate using $this->Event->find('all'); )
>>
>> Now suppose I want to remove from this set the "Event" with id "2".
>> How would I do this? I don't want to remove it from the DB, I just
>> want to remove it from the set, so it doesn't get displayed in the
>> view.
>>
>> I thought I could do this with Set::Remove. However the documentation
>> here is quite sparse. And doing a search for "Set::Remove" on both
>> the cakephp sites and this groups didn't turn up a single hit...
>>
>> Anyway, I tried:
>> Set::remove($events, '{n}.Event.id' , 2);
>>
>> But that didn't do anything.
>>
>> Any pointers to help me in the right direction?
>>
>> Krist
>>
>> --
>> krist.vanbesien@gmail.com
>> krist@vanbesien.org
>> Bremgarten b. Bern, Switzerland
>> --
>> A: It reverses the normal flow of conversation.
>> Q: What's wrong with top-posting?
>> A: Top-posting.
>> Q: What's the biggest scourge on plain text email discussions?
>>
>> >>
>>
>

--~--~---------~--~----~------------~-------~--~----~
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: