I've been experimenting with using SQL INSERTs and UPDATEs instead of using the Channel Entries API in my add-on. In one of my channels I am using a playa field which is simply connected to a separate channel (in this case, my contacts channel).
When using the Channel Entries API, I format the playa field like so:
$playa_field = Array('selections' => Array($entry_id));
This works perfectly every time. However, when you examine the output of this in the database, you get the following format:
[entry-id] [url-title] Full Name
e.g. [82] [joe-bloggs] Joe Bloggs
To create this format using the necessary variables I use the following code:
$formatted_contact = "[$entry_id] [".$meta['url_title']."] ".$e_data['contact_name'];
And embed it in the following query to insert a new item into my database:
$titleQ = $this->EE->db->query("INSERT INTO `exp_channel_titles` (`site_id`, `channel_id`, `author_id`, `title`, `url_title`, `status`, `entry_date`) VALUES ('1', '3', '".$meta['author_id']."', '".$touch_date.' '.$touch_type."', '".str_replace(' ', '-', $touch_date.' '.$touch_type)."', 'open', '$touch_date')");
$new_entry_id = $this->EE->db->insert_id();
echo 'new_entry_id is: '.$new_entry_id;
$entryQ = $this->EE->db->query("INSERT INTO `exp_channel_data` (`entry_id`, `site_id`, `channel_id`, `field_id_14`, `field_id_4`, `field_id_6`, `field_ft_6`, `field_id_48`, `field_id_49`, `field_id_53`, `field_id_52`) VALUES ('$new_entry_id', '1', '3', '$touch_date', '$touch_type', '$formatted_contact', 'none', '$touch_complete', '$touch_inactive', '$touch_comment', '$touch_source')");
All my code executes well enough from what I can see, however the playa field doesn't seem to get picked up along the way. If anyone can point out the potentially glaring formatting error it would be great! Please note, I am only looking at SQL as an alternative for the purposes of enhancing my system's speed and this will only be done in the background with little margin for error.
Cheers!