From 1bcfc081c9689f68cdcabc862781bbf0e9ba8cc8 Mon Sep 17 00:00:00 2001
From: David McReynolds <dave@thedaylightstudio.com>
Date: Thu, 23 Oct 2014 16:45:12 -0700
Subject: [PATCH] fixed issue with MY_Model::replace_placeholder method

---
 fuel/modules/fuel/core/MY_Model.php | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/fuel/modules/fuel/core/MY_Model.php b/fuel/modules/fuel/core/MY_Model.php
index b03c3ca9a..b697989c0 100755
--- a/fuel/modules/fuel/core/MY_Model.php
+++ b/fuel/modules/fuel/core/MY_Model.php
@@ -2822,7 +2822,6 @@ public function form_fields($values = array(), $related = array())
 						$order = $rel_config['order'];	
 					}
 				}
-
 				$related_model = $this->load_related_model($rel_config);
 				$related_options = $CI->$related_model->options_list(NULL, NULL, $where, $order);
 				$related_vals = ( ! empty($values['id'])) ? $this->get_related_keys($values, $related_model, 'belongs_to', $rel_config) : array();
@@ -4139,6 +4138,8 @@ protected function _is_nested_array($record)
 	 */	
 	public static function replace_placeholders($str, $values)
 	{
+		$return = $str;
+
 		if (is_string($str))
 		{
 			if (strpos($str, '{') !== FALSE)
@@ -4163,9 +4164,24 @@ public static function replace_placeholders($str, $values)
 			$return = array();
 			foreach($str as $key => $val)
 			{
-				if (isset($values[$key]))
+				if (strpos($val, '{') !== FALSE)
+				{
+					if (!empty($values))
+					{
+						foreach($values as $k => $v)
+						{
+							$return[$key] = str_replace('{'.$k.'}', $v, $val);	
+						}
+					}
+					else
+					{
+						// returns nothing to prevent SQL errors
+						$return = array();
+					}
+				}
+				else
 				{
-					$return[$key] = str_replace('{'.$key.'}', $values[$key], $val);	
+					$return[$key] = $val;
 				}
 			}
 		}