@@ -821,39 +821,43 @@ protected function buildUniqueExclusionRules(array $rules = array()) {
821
821
$ ruleset = (is_string ($ ruleset ))? explode ('| ' , $ ruleset ) : $ ruleset ;
822
822
823
823
foreach ($ ruleset as &$ rule ) {
824
- if (strpos ($ rule , 'unique: ' ) === 0 ) {
825
- // Stop splitting at 4 so final param will hold optional where clause
826
- $ params = explode (', ' , $ rule , 4 );
827
-
828
- $ uniqueRules = array ();
829
-
830
- // Append table name if needed
831
- $ table = explode (': ' , $ params [0 ]);
832
- if (count ($ table ) == 1 )
833
- $ uniqueRules [1 ] = $ this ->getTable ();
834
- else
835
- $ uniqueRules [1 ] = $ table [1 ];
836
-
837
- // Append field name if needed
838
- if (count ($ params ) == 1 )
839
- $ uniqueRules [2 ] = $ field ;
840
- else
841
- $ uniqueRules [2 ] = $ params [1 ];
842
-
843
- if (isset ($ this ->primaryKey )) {
844
- $ uniqueRules [3 ] = $ this ->{$ this ->primaryKey };
845
-
846
- // If optional where rules are passed, append them otherwise use primary key
847
- $ uniqueRules [4 ] = isset ($ params [3 ]) ? $ params [3 ] : $ this ->primaryKey ;
848
- }
849
- else {
850
- $ uniqueRules [3 ] = $ this ->id ;
824
+ if (strpos ($ rule , 'unique: ' ) === 0 ) {
825
+ // Stop splitting at 4 so final param will hold optional where clause
826
+ $ params = explode (', ' , $ rule , 4 );
827
+
828
+ $ uniqueRules = array ();
829
+
830
+ // Append table name if needed
831
+ $ table = explode (': ' , $ params [0 ]);
832
+ if (count ($ table ) == 1 ) {
833
+ $ uniqueRules [1 ] = $ this ->getTable ();
834
+ } else {
835
+ $ uniqueRules [1 ] = $ table [1 ];
836
+ }
837
+
838
+ // Append field name if needed
839
+ if (count ($ params ) == 1 ) {
840
+ $ uniqueRules [2 ] = $ field ;
841
+ } else {
842
+ $ uniqueRules [2 ] = $ params [1 ];
843
+ }
844
+
845
+ if (isset ($ this ->primaryKey )) {
846
+ if (isset ($ this ->{$ this ->primaryKey })) {
847
+ $ uniqueRules [3 ] = $ this ->{$ this ->primaryKey };
848
+
849
+ // If optional where rules are passed, append them otherwise use primary key
850
+ $ uniqueRules [4 ] = isset ($ params [3 ])? $ params [3 ] : $ this ->primaryKey ;
851
+ }
852
+ } else {
853
+ if (isset ($ this ->id )) {
854
+ $ uniqueRules [3 ] = $ this ->id ;
855
+ }
856
+ }
857
+
858
+ $ rule = 'unique: ' .implode (', ' , $ uniqueRules );
851
859
}
852
-
853
- $ rule = 'unique: ' . implode (', ' , $ uniqueRules );
854
- } // end if strpos unique
855
-
856
- } // end foreach ruleset
860
+ }
857
861
}
858
862
859
863
return $ rules ;
0 commit comments