@@ -362,7 +362,7 @@ private static function getClassIndex(\ReflectionClass $bean) : array
362362 {
363363 $ return = [];
364364
365- foreach ($ bean-> getAttributes ( \CoolBeans \Attribute \ClassIndex::class) as $ i => $ attribute ) {
365+ foreach (self :: getClassAttributes ( $ bean, \CoolBeans \Attribute \ClassIndex::class) as $ i => $ attribute ) {
366366 $ indexName = 'index_ ' . $ bean ->getShortName () . '_ ' . $ i ;
367367 $ columns = $ attribute ->newInstance ()->columns ;
368368 self ::validateColumnsExists ($ bean , $ columns );
@@ -395,7 +395,7 @@ private static function getClassUnique(\ReflectionClass $bean) : array
395395 {
396396 $ return = [];
397397
398- foreach ($ bean-> getAttributes ( \CoolBeans \Attribute \ClassUniqueConstraint::class) as $ index => $ attribute ) {
398+ foreach (self :: getClassAttributes ( $ bean, \CoolBeans \Attribute \ClassUniqueConstraint::class) as $ index => $ attribute ) {
399399 $ constraintName = 'unique_ ' . $ bean ->getShortName () . '_ ' . $ index ;
400400 $ columns = $ attribute ->newInstance ()->columns ;
401401 self ::validateColumnsExists ($ bean , $ columns );
@@ -423,6 +423,7 @@ private static function getCheck(\ReflectionProperty $property, string $beanName
423423 $ type ->getName () === 'string ' &&
424424 \count ($ property ->getAttributes (\CoolBeans \Attribute \AllowEmptyString::class)) === 0 ) {
425425 $ constraintName = 'check_ ' . $ beanName . '_ ' . $ property ->getName () . '_string_not_empty ' ;
426+
426427 $ return [] = self ::INDENTATION . 'CONSTRAINT ` ' . $ constraintName . '` CHECK (` ' . $ property ->name . '` != \'\') ' ;
427428 }
428429
@@ -433,7 +434,7 @@ private static function getClassCheck(\ReflectionClass $bean) : array
433434 {
434435 $ return = [];
435436
436- foreach ($ bean-> getAttributes ( \CoolBeans \Attribute \ClassCheckConstraint::class) as $ index => $ attribute ) {
437+ foreach (self :: getClassAttributes ( $ bean, \CoolBeans \Attribute \ClassCheckConstraint::class) as $ index => $ attribute ) {
437438 $ constraintName = 'check_ ' . $ bean ->getShortName () . '_ ' . $ index ;
438439
439440 $ return [] = self ::INDENTATION . 'CONSTRAINT ` ' . $ constraintName . '` CHECK ( ' . $ attribute ->newInstance ()->expression . ') ' ;
@@ -564,4 +565,17 @@ private function getBeans(string $destination) : array
564565
565566 return $ beans ;
566567 }
568+
569+ private static function getClassAttributes (\ReflectionClass $ bean , string $ attributeClass ) : array
570+ {
571+ $ return = $ bean ->getAttributes ($ attributeClass );
572+ $ parent = $ bean ->getParentClass ();
573+
574+ while ($ parent instanceof \ReflectionClass) {
575+ $ return = \array_merge ($ return , $ parent ->getAttributes ($ attributeClass ));
576+ $ parent = $ parent ->getParentClass ();
577+ }
578+
579+ return $ return ;
580+ }
567581}
0 commit comments