@@ -928,28 +928,33 @@ public function checkAttributeUniqueValue(AbstractAttribute $attribute, $object)
928
928
{
929
929
$ connection = $ this ->getConnection ();
930
930
$ select = $ connection ->select ();
931
- if ($ attribute ->getBackend ()->getType () === 'static ' ) {
931
+
932
+ $ entityIdField = $ this ->getEntityIdField ();
933
+ $ attributeBackend = $ attribute ->getBackend ();
934
+ if ($ attributeBackend ->getType () === 'static ' ) {
932
935
$ value = $ object ->getData ($ attribute ->getAttributeCode ());
933
936
$ bind = ['value ' => trim ($ value )];
934
937
935
938
$ select ->from (
936
939
$ this ->getEntityTable (),
937
- $ this -> getEntityIdField ()
940
+ $ entityIdField
938
941
)->where (
939
942
$ attribute ->getAttributeCode () . ' = :value '
940
943
);
941
944
} else {
942
945
$ value = $ object ->getData ($ attribute ->getAttributeCode ());
943
- if ($ attribute -> getBackend () ->getType () == 'datetime ' ) {
946
+ if ($ attributeBackend ->getType () == 'datetime ' ) {
944
947
$ value = (new \DateTime ($ value ))->format ('Y-m-d H:i:s ' );
945
948
}
946
949
$ bind = [
947
950
'attribute_id ' => $ attribute ->getId (),
948
951
'value ' => trim ($ value ),
949
952
];
953
+
954
+ $ entityIdField = $ object ->getResource ()->getLinkField ();
950
955
$ select ->from (
951
- $ attribute -> getBackend () ->getTable (),
952
- $ object -> getResource ()-> getLinkField ()
956
+ $ attributeBackend ->getTable (),
957
+ $ entityIdField
953
958
)->where (
954
959
'attribute_id = :attribute_id '
955
960
)->where (
@@ -964,9 +969,10 @@ public function checkAttributeUniqueValue(AbstractAttribute $attribute, $object)
964
969
965
970
$ data = $ connection ->fetchCol ($ select , $ bind );
966
971
967
- if ($ object ->getId ()) {
972
+ $ objectId = $ object ->getData ($ entityIdField );
973
+ if ($ objectId ) {
968
974
if (isset ($ data [0 ])) {
969
- return $ data [0 ] == $ object -> getId () ;
975
+ return $ data [0 ] == $ objectId ;
970
976
}
971
977
return true ;
972
978
}
0 commit comments