@@ -138,14 +138,19 @@ public function count(string $className): int {
138138 * @throws MultipleObjectsReturnedException
139139 */
140140 public function findByStorageIdAndRootId (string $ className , int $ storageId , int $ rootId ): Entity {
141- if (!in_array ('storage_id ' , $ className ::$ columns , true ) || !in_array ('node_id ' , $ className ::$ columns , true )) {
142- throw new \Exception ('entity does not have all required columns: storage_id, node_id ' );
141+ if (!in_array ('storage_id ' , $ className ::$ columns , true ) || ( !in_array ('root_id ' , $ className :: $ columns , true ) && ! in_array ( ' node_id ' , $ className ::$ columns , true ) )) {
142+ throw new \Exception ('entity does not have all required columns: storage_id, node_id/root_id ' );
143143 }
144144 $ qb = $ this ->db ->getQueryBuilder ();
145145 $ qb ->selectDistinct ($ className ::$ columns )
146146 ->from ($ className ::$ tableName )
147- ->where ($ qb ->expr ()->eq ('storage_id ' , $ qb ->createPositionalParameter ($ storageId , IQueryBuilder::PARAM_INT )))
148- ->andWhere ($ qb ->expr ()->eq ('root_id ' , $ qb ->createPositionalParameter ($ rootId , IQueryBuilder::PARAM_INT )));
147+ ->where ($ qb ->expr ()->eq ('storage_id ' , $ qb ->createPositionalParameter ($ storageId , IQueryBuilder::PARAM_INT )));
148+ if (in_array ('root_id ' , $ className ::$ columns , true )) {
149+ $ qb ->andWhere ($ qb ->expr ()->eq ('root_id ' , $ qb ->createPositionalParameter ($ rootId , IQueryBuilder::PARAM_INT )));
150+ }
151+ if (in_array ('node_id ' , $ className ::$ columns , true )) {
152+ $ qb ->andWhere ($ qb ->expr ()->eq ('node_id ' , $ qb ->createPositionalParameter ($ rootId , IQueryBuilder::PARAM_INT )));
153+ }
149154 return $ this ->findItem ($ className , $ qb );
150155 }
151156
0 commit comments