We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

api_channel_entries->update_entry.. anyway to not need to include all fields?

Development and Programming

timmaah's avatar
timmaah
6 posts
14 years ago
timmaah's avatar timmaah

I am using the channel entry api to sync a bit of data into ExpressionEngine. The problem seems to be that the update_entry call needs to have all data for the entry, otherwise the current data gets flattened.

For example.. Say I have a channel that has 10 channel fields..

If I try to update 1 via update_entry, the data in the other 9 gets lost..

$data = array(
    'channel_id' => 8,
    'title' => 'test',
    'entry_date' => time(),
   'field_id_1' => 'test data'
 );
$this->EE->api_channel_entries->update_entry(1, $data)

Produces a mysql update for exp_channel_data like:

UPDATE `exp_channel_data` SET `channel_id` = 8, `field_id_1` = 'test data', `field_id_2` = '', `field_id_3` = '', `field_id_4` = '', `field_id_5` = '', `field_id_6` = '', `field_id_7` = '', `field_id_8` = '', `field_id_9` = '', `field_id_10` = '', WHERE `entry_id` =  '1'

Is there anyway around this?

If not, the documentation should probably be updated to remove the word “required”

http://ellislab.com/expressionengine/user-guide/development/api/api_channel_entries.html#update-entry This function will update a channel entry. The data array must contain a title, an entry date, and data for all required fields.

Thanks -tim

[EDIT] Looking through the code, it appears this behavior is intended. Lines 928-929 of Api_channel_entries.php state:

// Make sure all the fields have a key in our data array even
  // if no data was sent

The next line it looks like this is bypassable if i set “autosave” to TRUE.

What is “autosave” and what would happen if I set it to TRUE? (I can’t find any documentation that relates to “autosave”) [/EDIT]

       
Dan Decker's avatar
Dan Decker
7,338 posts
14 years ago
Dan Decker's avatar Dan Decker

Hi timmaah,

We don’t generally offer support on Development issues, but I have an idea that might get you a workaround. If you sidestep the API and create the query statement directly, you should be able to update only the fields you intend.

$query = "UPDATE exp_channel_data SET channel_id = 8, title = 'test', entry_date = time(), field_id_1 = 'test date' WHERE entry_id = 1"
$this->EE->db->query($query);

That’s untested and off the top of my head, it may require some tweaks 😉

To better serve this thread, I’m going to move it over into Development and Programming to keep the discussion going.

Cheers!

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.