@@ -64,6 +64,7 @@ private function handleLinks(QueryBuilder $queryBuilder, array $identifiers, Que
64
64
65
65
$ previousAlias = $ alias ;
66
66
$ previousIdentifiers = end ($ links )->getIdentifiers ();
67
+ $ previousJoinProperty = $ doctrineClassMetadata ->getIdentifier ()[0 ];
67
68
$ expressions = [];
68
69
$ identifiers = array_reverse ($ identifiers );
69
70
@@ -73,14 +74,10 @@ private function handleLinks(QueryBuilder $queryBuilder, array $identifiers, Que
73
74
}
74
75
75
76
$ identifierProperties = $ link ->getIdentifiers ();
76
- $ currentAlias = $ queryNameGenerator ->generateJoinAlias ($ alias );
77
-
78
- if ($ link ->getFromClass () === $ resourceClass ) {
79
- $ currentAlias = $ alias ;
80
- }
81
77
82
78
if (!$ link ->getFromProperty () && !$ link ->getToProperty ()) {
83
79
$ doctrineClassMetadata = $ manager ->getClassMetadata ($ link ->getFromClass ());
80
+ $ currentAlias = $ link ->getFromClass () === $ resourceClass ? $ alias : $ queryNameGenerator ->generateJoinAlias ($ alias );
84
81
85
82
foreach ($ identifierProperties as $ identifierProperty ) {
86
83
$ placeholder = $ queryNameGenerator ->generateParameterName ($ identifierProperty );
@@ -90,22 +87,24 @@ private function handleLinks(QueryBuilder $queryBuilder, array $identifiers, Que
90
87
91
88
$ previousAlias = $ currentAlias ;
92
89
$ previousIdentifiers = $ identifierProperties ;
90
+ $ previousJoinProperty = $ doctrineClassMetadata ->getIdentifier ()[0 ];
93
91
continue ;
94
92
}
95
93
96
94
if (1 < \count ($ previousIdentifiers ) || 1 < \count ($ identifierProperties )) {
97
- throw new RuntimeException ('Composite identifiers on a relation can not be handled automatically, implement your own query. ' );
95
+ throw new RuntimeException ('Multiple identifiers on a relation can not be handled automatically, implement your own query. ' );
98
96
}
99
97
100
98
$ previousIdentifier = $ previousIdentifiers [0 ];
101
99
$ identifierProperty = $ identifierProperties [0 ];
100
+ $ joinProperty = $ doctrineClassMetadata ->getIdentifier ()[0 ];
102
101
$ placeholder = $ queryNameGenerator ->generateParameterName ($ identifierProperty );
103
102
104
103
if ($ link ->getFromProperty () && !$ link ->getToProperty ()) {
105
104
$ doctrineClassMetadata = $ manager ->getClassMetadata ($ link ->getFromClass ());
106
105
$ joinAlias = $ queryNameGenerator ->generateJoinAlias ('m ' );
107
- $ assocationMapping = $ doctrineClassMetadata ->getAssociationMappings ()[ $ link ->getFromProperty ()] ;
108
- $ relationType = $ assocationMapping ['type ' ];
106
+ $ associationMapping = $ doctrineClassMetadata ->getAssociationMapping ( $ link ->getFromProperty ()) ;
107
+ $ relationType = $ associationMapping ['type ' ];
109
108
110
109
if ($ relationType & ClassMetadataInfo::TO_MANY ) {
111
110
$ nextAlias = $ queryNameGenerator ->generateJoinAlias ($ alias );
@@ -116,21 +115,22 @@ private function handleLinks(QueryBuilder $queryBuilder, array $identifiers, Que
116
115
}
117
116
118
117
// A single-valued association path expression to an inverse side is not supported in DQL queries.
119
- if ($ relationType & ClassMetadataInfo::TO_ONE && !$ assocationMapping ['isOwningSide ' ]) {
120
- $ queryBuilder ->innerJoin ("$ previousAlias. " .$ assocationMapping ['mappedBy ' ], $ joinAlias );
118
+ if ($ relationType & ClassMetadataInfo::TO_ONE && !( $ associationMapping ['isOwningSide ' ] ?? true ) ) {
119
+ $ queryBuilder ->innerJoin ("$ previousAlias. " .$ associationMapping ['mappedBy ' ], $ joinAlias );
121
120
} else {
122
121
$ queryBuilder ->join (
123
122
$ link ->getFromClass (),
124
123
$ joinAlias ,
125
124
'with ' ,
126
- "{$ previousAlias }. {$ previousIdentifier } = $ joinAlias. {$ link ->getFromProperty ()}"
125
+ "{$ previousAlias }. {$ previousJoinProperty } = $ joinAlias. {$ link ->getFromProperty ()}"
127
126
);
128
127
}
129
128
130
129
$ queryBuilder ->andWhere ("$ joinAlias. $ identifierProperty = : $ placeholder " );
131
130
$ queryBuilder ->setParameter ($ placeholder , array_shift ($ identifiers ), $ doctrineClassMetadata ->getTypeOfField ($ identifierProperty ));
132
131
$ previousAlias = $ joinAlias ;
133
132
$ previousIdentifier = $ identifierProperty ;
133
+ $ previousJoinProperty = $ joinProperty ;
134
134
continue ;
135
135
}
136
136
@@ -140,6 +140,7 @@ private function handleLinks(QueryBuilder $queryBuilder, array $identifiers, Que
140
140
$ queryBuilder ->setParameter ($ placeholder , array_shift ($ identifiers ), $ doctrineClassMetadata ->getTypeOfField ($ identifierProperty ));
141
141
$ previousAlias = $ joinAlias ;
142
142
$ previousIdentifier = $ identifierProperty ;
143
+ $ previousJoinProperty = $ joinProperty ;
143
144
}
144
145
145
146
if ($ expressions ) {
0 commit comments