You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					68 lines
				
				2.2 KiB
			
		
		
			
		
	
	
					68 lines
				
				2.2 KiB
			| 
								 
											13 years ago
										 
									 | 
							
								<?php
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @link http://www.yiiframework.com/
							 | 
						||
| 
								 
											12 years ago
										 
									 | 
							
								 * @copyright Copyright (c) 2008 Yii Software LLC
							 | 
						||
| 
								 
											13 years ago
										 
									 | 
							
								 * @license http://www.yiiframework.com/license/
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											12 years ago
										 
									 | 
							
								namespace yii\redis;
							 | 
						||
| 
								 
											12 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											12 years ago
										 
									 | 
							
								use yii\db\ActiveRelationInterface;
							 | 
						||
| 
								 | 
							
								use yii\db\ActiveRelationTrait;
							 | 
						||
| 
								 
											12 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 
											13 years ago
										 
									 | 
							
								/**
							 | 
						||
| 
								 
											12 years ago
										 
									 | 
							
								 * ActiveRelation represents a relation between two Active Record classes.
							 | 
						||
| 
								 | 
							
								 *
							 | 
						||
| 
								 | 
							
								 * ActiveRelation instances are usually created by calling [[ActiveRecord::hasOne()]] and
							 | 
						||
| 
								 | 
							
								 * [[ActiveRecord::hasMany()]]. An Active Record class declares a relation by defining
							 | 
						||
| 
								 | 
							
								 * a getter method which calls one of the above methods and returns the created ActiveRelation object.
							 | 
						||
| 
								 | 
							
								 *
							 | 
						||
| 
								 | 
							
								 * A relation is specified by [[link]] which represents the association between columns
							 | 
						||
| 
								 | 
							
								 * of different tables; and the multiplicity of the relation is indicated by [[multiple]].
							 | 
						||
| 
								 | 
							
								 *
							 | 
						||
| 
								 | 
							
								 * If a relation involves a pivot table, it may be specified by [[via()]] or [[viaTable()]] method.
							 | 
						||
| 
								 
											13 years ago
										 
									 | 
							
								 *
							 | 
						||
| 
								 | 
							
								 * @author Carsten Brandt <mail@cebe.cc>
							 | 
						||
| 
								 | 
							
								 * @since 2.0
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 
											12 years ago
										 
									 | 
							
								class ActiveRelation extends ActiveQuery implements ActiveRelationInterface
							 | 
						||
| 
								 
											13 years ago
										 
									 | 
							
								{
							 | 
						||
| 
								 
											12 years ago
										 
									 | 
							
									use ActiveRelationTrait;
							 | 
						||
| 
								 
											12 years ago
										 
									 | 
							
								
							 | 
						||
| 
								 | 
							
									/**
							 | 
						||
| 
								 
											12 years ago
										 
									 | 
							
									 * Executes a script created by [[LuaScriptBuilder]]
							 | 
						||
| 
								 | 
							
									 * @param Connection $db the database connection used to execute the query.
							 | 
						||
| 
								 | 
							
									 * If this parameter is not given, the `db` application component will be used.
							 | 
						||
| 
								 | 
							
									 * @param string $type the type of the script to generate
							 | 
						||
| 
								 | 
							
									 * @param null $column
							 | 
						||
| 
								 | 
							
									 * @return array|bool|null|string
							 | 
						||
| 
								 
											13 years ago
										 
									 | 
							
									 */
							 | 
						||
| 
								 
											12 years ago
										 
									 | 
							
									protected function executeScript($db, $type, $column=null)
							 | 
						||
| 
								 
											12 years ago
										 
									 | 
							
									{
							 | 
						||
| 
								 | 
							
										if ($this->primaryModel !== null) {
							 | 
						||
| 
								 | 
							
											// lazy loading
							 | 
						||
| 
								 | 
							
											if ($this->via instanceof self) {
							 | 
						||
| 
								 | 
							
												// via pivot table
							 | 
						||
| 
								 
											12 years ago
										 
									 | 
							
												$viaModels = $this->via->findPivotRows([$this->primaryModel]);
							 | 
						||
| 
								 
											12 years ago
										 
									 | 
							
												$this->filterByModels($viaModels);
							 | 
						||
| 
								 | 
							
											} elseif (is_array($this->via)) {
							 | 
						||
| 
								 | 
							
												// via relation
							 | 
						||
| 
								 
											12 years ago
										 
									 | 
							
												/** @var ActiveRelation $viaQuery */
							 | 
						||
| 
								 
											12 years ago
										 
									 | 
							
												list($viaName, $viaQuery) = $this->via;
							 | 
						||
| 
								 | 
							
												if ($viaQuery->multiple) {
							 | 
						||
| 
								 | 
							
													$viaModels = $viaQuery->all();
							 | 
						||
| 
								 | 
							
													$this->primaryModel->populateRelation($viaName, $viaModels);
							 | 
						||
| 
								 | 
							
												} else {
							 | 
						||
| 
								 | 
							
													$model = $viaQuery->one();
							 | 
						||
| 
								 | 
							
													$this->primaryModel->populateRelation($viaName, $model);
							 | 
						||
| 
								 
											12 years ago
										 
									 | 
							
													$viaModels = $model === null ? [] : [$model];
							 | 
						||
| 
								 
											12 years ago
										 
									 | 
							
												}
							 | 
						||
| 
								 | 
							
												$this->filterByModels($viaModels);
							 | 
						||
| 
								 | 
							
											} else {
							 | 
						||
| 
								 
											12 years ago
										 
									 | 
							
												$this->filterByModels([$this->primaryModel]);
							 | 
						||
| 
								 
											13 years ago
										 
									 | 
							
											}
							 | 
						||
| 
								 | 
							
										}
							 | 
						||
| 
								 
											12 years ago
										 
									 | 
							
										return parent::executeScript($db, $type, $column);
							 | 
						||
| 
								 
											12 years ago
										 
									 | 
							
									}
							 | 
						||
| 
								 
											13 years ago
										 
									 | 
							
								}
							 |