33 if (isset ( self::getModelMetadata ( $class ) [
'#joinTable'] )) {
35 foreach ( $jts as $jt ) {
36 $result [] = $jt [
'name'];
44 foreach ( $models as $model ) {
45 $result = \array_merge ( $result, self::getJoinTables ( $model ) );
53 if ($manyToOne = self::getAnnotationInfo ( $class,
'#manyToOne' )) {
54 $result = \array_merge ( $result, $manyToOne );
56 if ($oneToMany = self::getAnnotationInfo ( $class,
'#oneToMany' )) {
57 $result = \array_merge ( $result, \array_keys ( $oneToMany ) );
59 if ($manyToMany = self::getAnnotationInfo ( $class,
'#manyToMany' )) {
60 $result = \array_merge ( $result, \array_keys ( $manyToMany ) );
69 if ($manyToOne = self::getAnnotationInfo ( $class,
'#manyToOne' )) {
70 foreach ( $manyToOne as $oneField ) {
71 $field = $joinColumns [$oneField] [
'name'];
72 $result [$field] = $invertedJoinColumns [$field];
73 $result [$oneField] = $invertedJoinColumns [$field];
76 if ($oneToMany = self::getAnnotationInfo ( $class,
'#oneToMany' )) {
77 $result = \array_merge ( $result, $oneToMany );
79 if ($manyToMany = self::getAnnotationInfo ( $class,
'#manyToMany' )) {
80 $result = \array_merge ( $result, $manyToMany );
91 if ($manyToOne = self::getAnnotationInfo ( $class,
'#manyToOne' )) {
92 foreach ( $manyToOne as $member ) {
94 $result [$joinColumn [
'name']] = $member;
97 if ($manyToMany = self::getAnnotationInfo ( $class,
"#manyToMany" )) {
98 $manyToMany = array_keys ( $manyToMany );
99 foreach ( $manyToMany as $member ) {
100 $result [$member .
'Ids'] = $member;
103 if ($oneToMany = self::getAnnotationInfo ( $class,
'#oneToMany' )) {
104 $oneToMany = array_keys ( $oneToMany );
105 foreach ( $oneToMany as $member ) {
106 $result [$member .
'Ids'] = $member;
109 return [
'relations' => $result,
'manyToOne' => $manyToOne,
'manyToMany' => $manyToMany,
'oneToMany' => $oneToMany ];
114 if ($manyToOnes = self::getAnnotationInfo ( $class,
'#manyToOne' )) {
116 foreach ( $manyToOnes as $manyToOne ) {
117 if (isset ( $joinColumns [$manyToOne] )) {
118 $result [$manyToOne] = [
'type' =>
'manyToOne',
'value' => $joinColumns [$manyToOne] ];
122 if ($oneToManys = self::getAnnotationInfo ( $class,
'#oneToMany' )) {
123 foreach ( $oneToManys as $field => $oneToMany ) {
124 $result [$field] = [
'type' =>
'oneToMany',
'value' => $oneToMany ];
127 if ($manyToManys = self::getAnnotationInfo ( $class,
"#manyToMany" )) {
128 foreach ( $manyToManys as $field => $manyToMany ) {
129 $result [$field] = [
'type' =>
'manyToMany',
'value' => $manyToMany ];
135 public static function getUJoinSQL($db, $model, $arrayAnnot, $field, &$aliases, $quote) {
136 $type = $arrayAnnot [
'type'];
137 $annot = $arrayAnnot [
'value'];
139 $tableAlias = (isset ( $aliases [$table] )) ? $aliases [$table] : $table;
140 if ($type ===
'manyToOne') {
141 $fkClass = $annot [
'className'];
143 $fkField = $annot [
'name'];
146 $result =
"LEFT JOIN {$quote}{$fkTable}{$quote} {$quote}{$alias}{$quote} ON {$quote}{$tableAlias}{$quote}.{$quote}{$fkField}{$quote}={$quote}{$alias}{$quote}.{$quote}{$pkField}{$quote}";
147 } elseif ($type ===
'oneToMany') {
148 $fkClass = $annot [
'className'];
151 $fkField = $fkAnnot [
'name'];
154 $result =
"LEFT JOIN {$quote}{$fkTable}{$quote} {$quote}{$alias}{$quote} ON {$quote}{$tableAlias}{$quote}.{$quote}{$pkField}{$quote}={$quote}{$alias}{$quote}.{$quote}{$fkField}{$quote}";
157 $parser->init ( $annot );
158 $fkTable = $parser->getTargetEntityTable ();
159 $fkClass = $parser->getTargetEntityClass ();
161 $result = $parser->getSQL ( $alias, $aliases );
164 if (array_search ( $alias, $aliases ) !==
false) {
167 $aliases [$fkTable] = $alias;
168 return [
'class' => $fkClass,
'table' => $fkTable,
'sql' => $result,
'alias' => $alias ];
172 return \uniqid ( $fkTable .
'_' . $table [0] );
183 foreach ($infos as $f=>$annot){
184 if(\array_search(
'remove',$annot[
'cascade']??[])!==
false){
198 if ($result !==
false)
199 return \array_keys ( $result );
204 return 'id' . \ucfirst ( self::getTableName ( $classname ) );
208 if (! isset ( $metaDatas )) {
209 if (\is_object ( $instance )) {
210 $class = \get_class ( $instance );
216 $invertedJoinColumns = $metaDatas [
'#invertedJoinColumn'];
217 foreach ( $invertedJoinColumns as $field => $invertedJoinColumn ) {
218 if ($invertedJoinColumn [
'member'] === $member) {
219 return [ $field,$invertedJoinColumn ];
232 $class = \get_class ( $instance );
234 if ($members !==
false) {
235 foreach ( $members as $member ) {
236 $memberAccessor =
'get' . ucfirst ( $member );
237 if (\method_exists ( $instance, $memberAccessor )) {
238 $memberInstance = $instance->$memberAccessor ();
239 if (isset ( $memberInstance ) ){
240 if(\is_object ( $memberInstance )) {
242 if (\count($keyValues) > 0) {
244 $ret [$fkName] = \current($keyValues);
248 $ret [$fkName] = $memberInstance;
250 } elseif (self::isNullable ( $class, $member )) {
252 $ret [$fkName] =
null;
262 if ($annot !==
false) {
263 $fkName = $annot [
'name'];
265 $fkName =
'id' . \ucfirst ( self::getTableName ( \ucfirst ( $member ) ) );
272 $pks=$metas[
'#primaryKeys'];
273 $manyToOnes=$metas[
'#manyToOne'];
274 $manysCount=\count($manyToOnes);
277 foreach ($manyToOnes as $manyToOne) {
278 $len = \strlen($manyToOne);
279 foreach ($pks as $k) {
280 if (\substr($k, -$len) === \ucfirst($manyToOne)) {
291 $fields=self::getSerializableMembers($manyClass);
292 $joinColumns=self::getModelMetadata($manyClass)[
'#joinColumn'];
293 foreach ($joinColumns as $joinColumn){
294 if($joinColumn[
'className']===$class){
295 if($index=\array_search($joinColumn[
'name'],$fields)!==
false){
296 unset($fields[$index]);
300 return \array_values($fields);
static getManyToOneMembersAndValues($instance)
static getAnnotationInfo($class, $keyAnnotation)
static getRemoveCascadeFields($class, $keyAnnotation='#oneToMany')
static getJoinTables($class)
static getTableName($class)
static getDefaultFk($classname)
static getMemberJoinColumns($instance, $member, $metaDatas=NULL)
static getUJoinSQL($db, $model, $arrayAnnot, $field, &$aliases, $quote)
static getOneToManyFields($class)
static getFieldsInRelations_($class)
static isManyToMany($class)
static getManyToManyFields($class)
static getFirstKey($class)
static getManyToManyFieldsDt($class, $manyClass)
static getRelationInfos($class)
static getAnnotFieldsInRelations($class)
static getJoinColumnName($class, $member)
static getFieldsInRelationsForUpdate_($class)
static getKeyFieldsAndValues($instance)
static getModelMetadata($className)
static getManyToOneFields($class)
static getAllJoinTables($models)
static getJoinAlias($table, $fkTable)
static getFieldsInRelations($class)
static getAnnotationInfoMember($class, $keyAnnotation, $member)
Ubiquity\orm\traits This class is part of Ubiquity.