| @@ 67-90 (lines=24) @@ | ||
| 64 | * @param string $from |
|
| 65 | * @return $this |
|
| 66 | */ |
|
| 67 | public function from($from) |
|
| 68 | { |
|
| 69 | // $from can either be |
|
| 70 | // a) a field name indicating a reference to a different document. Currently, only REFERENCE_STORE_AS_ID is supported |
|
| 71 | // b) a Class name |
|
| 72 | // c) a collection name |
|
| 73 | // In cases b) and c) the local and foreign fields need to be filled |
|
| 74 | if ($this->class->hasReference($from)) { |
|
| 75 | return $this->fromReference($from); |
|
| 76 | } |
|
| 77 | ||
| 78 | // Check if mapped class with given name exists |
|
| 79 | try { |
|
| 80 | $this->targetClass = $this->dm->getClassMetadata($from); |
|
| 81 | } catch (BaseMappingException $e) { |
|
| 82 | return parent::from($from); |
|
| 83 | } |
|
| 84 | ||
| 85 | if ($this->targetClass->isSharded()) { |
|
| 86 | throw MappingException::cannotUseShardedCollectionInLookupStages($this->targetClass->name); |
|
| 87 | } |
|
| 88 | ||
| 89 | return parent::from($this->targetClass->getCollection()); |
|
| 90 | } |
|
| 91 | ||
| 92 | public function connectFromField($connectFromField) |
|
| 93 | { |
|
| @@ 68-91 (lines=24) @@ | ||
| 65 | * @param string $from |
|
| 66 | * @return $this |
|
| 67 | */ |
|
| 68 | public function from($from) |
|
| 69 | { |
|
| 70 | // $from can either be |
|
| 71 | // a) a field name indicating a reference to a different document. Currently, only REFERENCE_STORE_AS_ID is supported |
|
| 72 | // b) a Class name |
|
| 73 | // c) a collection name |
|
| 74 | // In cases b) and c) the local and foreign fields need to be filled |
|
| 75 | if ($this->class->hasReference($from)) { |
|
| 76 | return $this->fromReference($from); |
|
| 77 | } |
|
| 78 | ||
| 79 | // Check if mapped class with given name exists |
|
| 80 | try { |
|
| 81 | $this->targetClass = $this->dm->getClassMetadata($from); |
|
| 82 | } catch (BaseMappingException $e) { |
|
| 83 | return parent::from($from); |
|
| 84 | } |
|
| 85 | ||
| 86 | if ($this->targetClass->isSharded()) { |
|
| 87 | throw MappingException::cannotUseShardedCollectionInLookupStages($this->targetClass->name); |
|
| 88 | } |
|
| 89 | ||
| 90 | return parent::from($this->targetClass->getCollection()); |
|
| 91 | } |
|
| 92 | ||
| 93 | /** |
|
| 94 | * @param string $fieldName |
|