Wednesday, August 7, 2013

Problem with save method

Hi!

I am a new bee in cakePHP, look at following scenario

I have following tables structure

-------------------------------------------------------------------------------------------------------------------------------------------------------
Table name: events
Field Type Null Default Comments
id int(11) No    Contains id of Event 
category_id int(11) No    Contains id of category to which event belongs 
client_id int(11) No    Contains id of client to which event belongs 
name varchar(255) No    Contains name of Event 
venue varchar(255) No    Contains venue of event 
description text No    Contains description of event 
image varchar(255) No  no_image.jpg  contains name of image 
start_date date No    Contains start date of event 
end_date date No    Contains end date of event 
created datetime No    Contains date when event was added 
modified datetime No    Contains date when event was last modified 
-------------------------------------------------------------------------------------------------------------------------------------------------------

When adding an event, i want to save all fields except 'image',, to do so i am trying to save method with syntax

$this->Event->save($this->request->data, true, array("Event.name", "Event.venue", "Event.description", "Event.start_date", "Event.end_date", "Event.created", "Event.modified", "Event.category_id", "Event.client_id"))

But this statement result in

INSERT INTO `mydb`.`events` (`modified`, `created`) VALUES ('2013-08-07 18:20:39', '2013-08-07 18:20:39')

instead of

INSERT INTO `mydb`.`events` (`category_id`, `client_id`, `name`, `venue`, `description`, `start_date`, `end_date`, `modified`, `created`) VALUES (1, 1, 'My Event', 'Jaipur', 'My Event at Jaipur', '2013-08-07', '2013-08-07', '2013-08-07 18:20:39', '2013-08-07 18:20:39')

Also when i try to update image field like

$this->Event->save(array("Event"=>array("id"=>$this->Event->id, "image"=>"myimage.jpg", true)))

it produces query like

UPDATE `mydb`.`events` SET `id` = 84  WHERE `mydb`.`events`.`id` = '84'


i am highly tired, please help me thanks in advanced.

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments: