Re: How to exclude a field from inserts and updates

2008-10-08 Thread R. Davila

teknoid wrote:
> While this works fine, and makes your app more secure... the real
> question is why are you passing fields that do not need saving to the
> controller? or why do you even have them in the form?

I'm not. I used "cake bake" to make a skeleton controller and view.
CakePHP automatically added all the fields to the add and edit views.

I removed the fields I don't want from the views, but the save()
function still tries to save an empty value for that field.

I tried to unset() the fields I didn't want from $this->data, but it
didn't stop CakePHP from saving an empty value into those fields.

By passing a list of the fields I want to the save() function, I'm
actually telling CakePHP not to save the other fields which is exactly
what I want.



> 
> 
> On Oct 7, 7:50 pm, "R. Davila" <[EMAIL PROTECTED]> wrote:
>> The answer was to pass an array of field names to save().
>>
>> save($this->data, true, array('field_a', 'field_b'));
>>
>> That way field_c is excluded from the save.
>>
>> Thanks!
>>
>> teknoid wrote:
>>> Is the field in the data array?
>>> Cake also has a white list of fields param you can (and should) pass
>>> to save().
>>> On Oct 7, 7:00 pm, "R. Davila" <[EMAIL PROTECTED]> wrote:
 Hi,
 I have a table with a timestamp field which is managed by MySQL.
 This is the definition of the field:
 `fieldname` timestamp NOT NULL default CURRENT_TIMESTAMP on update 
 CURRENT_TIMESTAMP
 When a new record is inserted, MySQL fills in the default value for the 
 field.
 When the record is updated, MySQL updates the field value accordingly.
 I need to tell CakePHPnot to include that fieldin the inserts and updates, 
 otherwise MySQL does not assign the values it should.
 The timestamp field is just an example since the behavior I'm looking for 
 would be needed for any computed field in the table.
 Thanks in advance
>>> 
>>> No virus found in this incoming message.
>>> Checked by AVG -http://www.avg.com
>>> Version: 8.0.173 / Virus Database: 270.7.6/1713 - Release Date: 10/7/2008 
>>> 6:40 PM
> > 
> 
> 
> 
> 
> No virus found in this incoming message.
> Checked by AVG - http://www.avg.com 
> Version: 8.0.173 / Virus Database: 270.7.6/1715 - Release Date: 10/8/2008 
> 7:19 PM
> 

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: How to exclude a field from inserts and updates

2008-10-08 Thread Hipnotik

Interesting subject...

On Oct 8, 7:26 am, "Paolo Stancato" <[EMAIL PROTECTED]> wrote:
> Maybe you're not passing those fileds but someone else.
> It's quiete easy to inject new fields in a form.

How adding process should be done correctly?
Is 'cake bake'-way incorrect? Working but incorrect?

> Cheers
>
> 2008/10/7 teknoid <[EMAIL PROTECTED]>:
>
>
>
>
>
> > While this works fine, and makes your app more secure... the real
> > question is why are you passing fields that do not need saving to the
> > controller? or why do you even have them in the form?

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: How to exclude a field from inserts and updates

2008-10-07 Thread Paolo Stancato

Maybe you're not passing those fileds but someone else.
It's quiete easy to inject new fields in a form.

Cheers

2008/10/7 teknoid <[EMAIL PROTECTED]>:
>
> While this works fine, and makes your app more secure... the real
> question is why are you passing fields that do not need saving to the
> controller? or why do you even have them in the form?

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: How to exclude a field from inserts and updates

2008-10-07 Thread teknoid

While this works fine, and makes your app more secure... the real
question is why are you passing fields that do not need saving to the
controller? or why do you even have them in the form?


On Oct 7, 7:50 pm, "R. Davila" <[EMAIL PROTECTED]> wrote:
> The answer was to pass an array of field names to save().
>
>         save($this->data, true, array('field_a', 'field_b'));
>
> That way field_c is excluded from the save.
>
> Thanks!
>
> teknoid wrote:
> > Is the field in the data array?
> > Cake also has a white list of fields param you can (and should) pass
> > to save().
>
> > On Oct 7, 7:00 pm, "R. Davila" <[EMAIL PROTECTED]> wrote:
> >> Hi,
> >> I have a table with a timestamp field which is managed by MySQL.
> >> This is the definition of the field:
> >>     `fieldname` timestamp NOT NULL default CURRENT_TIMESTAMP on update 
> >> CURRENT_TIMESTAMP
> >> When a new record is inserted, MySQL fills in the default value for the 
> >> field.
> >> When the record is updated, MySQL updates the field value accordingly.
> >> I need to tell CakePHPnot to include that fieldin the inserts and updates, 
> >> otherwise MySQL does not assign the values it should.
> >> The timestamp field is just an example since the behavior I'm looking for 
> >> would be needed for any computed field in the table.
> >> Thanks in advance
>
> > 
>
> > No virus found in this incoming message.
> > Checked by AVG -http://www.avg.com
> > Version: 8.0.173 / Virus Database: 270.7.6/1713 - Release Date: 10/7/2008 
> > 6:40 PM
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



How to exclude a field from inserts and updates

2008-10-07 Thread R. Davila





Hi,

I have a table with a timestamp field which is managed by MySQL.
This is the definition of the field:
    `fieldname` timestamp NOT NULL default CURRENT_TIMESTAMP on update
CURRENT_TIMESTAMP

When a new record is inserted, MySQL fills in the default value for the
field.
When the record is updated, MySQL updates the field value accordingly.

I need to tell CakePHP not to include that field in the inserts
and updates, otherwise MySQL does not assign the values it should.

The timestamp field is just an example since the behavior I'm looking
for would be needed for any computed field in the table.

Thanks in advance

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]  For more options, visit this group at http://groups.google.com/group/cake-php?hl=en  -~--~~~~--~~--~--~---





Re: How to exclude a field from inserts and updates

2008-10-07 Thread R. Davila

The answer was to pass an array of field names to save().

save($this->data, true, array('field_a', 'field_b'));

That way field_c is excluded from the save.

Thanks!

teknoid wrote:
> Is the field in the data array?
> Cake also has a white list of fields param you can (and should) pass
> to save().
> 
> On Oct 7, 7:00 pm, "R. Davila" <[EMAIL PROTECTED]> wrote:
>> Hi,
>> I have a table with a timestamp field which is managed by MySQL.
>> This is the definition of the field:
>> `fieldname` timestamp NOT NULL default CURRENT_TIMESTAMP on update 
>> CURRENT_TIMESTAMP
>> When a new record is inserted, MySQL fills in the default value for the 
>> field.
>> When the record is updated, MySQL updates the field value accordingly.
>> I need to tell CakePHPnot to include that fieldin the inserts and updates, 
>> otherwise MySQL does not assign the values it should.
>> The timestamp field is just an example since the behavior I'm looking for 
>> would be needed for any computed field in the table.
>> Thanks in advance
> > 
> 
> 
> 
> 
> No virus found in this incoming message.
> Checked by AVG - http://www.avg.com 
> Version: 8.0.173 / Virus Database: 270.7.6/1713 - Release Date: 10/7/2008 
> 6:40 PM
> 

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: How to exclude a field from inserts and updates

2008-10-07 Thread R. Davila

I'm passing $this->data to the save() function.
The controller is the default made by "cake bake" which includes the
following in the add() function:

 function add() {
  if (!empty ($this->data)) {
   $this->Status->create();
   if ($this->Status->save($this->data)) {
   ...

If I take a field param out of the $this->data array, will it be
excluded from the insert or update?


teknoid wrote:
> Is the field in the data array?
> Cake also has a white list of fields param you can (and should) pass
> to save().
>
> On Oct 7, 7:00 pm, "R. Davila" <[EMAIL PROTECTED]> wrote:
>   
>> Hi,
>> I have a table with a timestamp field which is managed by MySQL.
>> This is the definition of the field:
>> `fieldname` timestamp NOT NULL default CURRENT_TIMESTAMP on update 
>> CURRENT_TIMESTAMP
>> When a new record is inserted, MySQL fills in the default value for the 
>> field.
>> When the record is updated, MySQL updates the field value accordingly.
>> I need to tell CakePHPnot to include that fieldin the inserts and updates, 
>> otherwise MySQL does not assign the values it should.
>> The timestamp field is just an example since the behavior I'm looking for 
>> would be needed for any computed field in the table.
>> Thanks in advance
>> 
> >   
> 
>
>
> No virus found in this incoming message.
> Checked by AVG - http://www.avg.com 
> Version: 8.0.173 / Virus Database: 270.7.6/1713 - Release Date: 10/7/2008 
> 6:40 PM
>
>   

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: How to exclude a field from inserts and updates

2008-10-07 Thread teknoid

Is the field in the data array?
Cake also has a white list of fields param you can (and should) pass
to save().

On Oct 7, 7:00 pm, "R. Davila" <[EMAIL PROTECTED]> wrote:
> Hi,
> I have a table with a timestamp field which is managed by MySQL.
> This is the definition of the field:
>     `fieldname` timestamp NOT NULL default CURRENT_TIMESTAMP on update 
> CURRENT_TIMESTAMP
> When a new record is inserted, MySQL fills in the default value for the field.
> When the record is updated, MySQL updates the field value accordingly.
> I need to tell CakePHPnot to include that fieldin the inserts and updates, 
> otherwise MySQL does not assign the values it should.
> The timestamp field is just an example since the behavior I'm looking for 
> would be needed for any computed field in the table.
> Thanks in advance
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---