@@ -23,6 +23,9 @@ class Selection implements \Iterator, IRowContainer, \ArrayAccess, \Countable
2323 use Nette \SmartObject;
2424
2525 /** @var Explorer */
26+ protected $ explorer ;
27+
28+ /** @var Explorer back compatibility */
2629 protected $ context ;
2730
2831 /** @var IConventions */
@@ -89,7 +92,7 @@ public function __construct(
8992 string $ tableName ,
9093 Nette \Caching \IStorage $ cacheStorage = null
9194 ) {
92- $ this ->context = $ explorer ;
95+ $ this ->explorer = $ this -> context = $ explorer ;
9396 $ this ->conventions = $ conventions ;
9497 $ this ->name = $ tableName ;
9598
@@ -135,7 +138,7 @@ public function getPrimary(bool $throw = true)
135138 public function getPrimarySequence (): ?string
136139 {
137140 if ($ this ->primarySequence === false ) {
138- $ this ->primarySequence = $ this ->context ->getStructure ()->getPrimaryKeySequence ($ this ->name );
141+ $ this ->primarySequence = $ this ->explorer ->getStructure ()->getPrimaryKeySequence ($ this ->name );
139142 }
140143
141144 return $ this ->primarySequence ;
@@ -579,19 +582,19 @@ protected function createRow(array $row): ActiveRow
579582
580583 public function createSelectionInstance (string $ table = null ): self
581584 {
582- return new self ($ this ->context , $ this ->conventions , $ table ?: $ this ->name , $ this ->cache ? $ this ->cache ->getStorage () : null );
585+ return new self ($ this ->explorer , $ this ->conventions , $ table ?: $ this ->name , $ this ->cache ? $ this ->cache ->getStorage () : null );
583586 }
584587
585588
586589 protected function createGroupedSelectionInstance (string $ table , string $ column ): GroupedSelection
587590 {
588- return new GroupedSelection ($ this ->context , $ this ->conventions , $ table , $ column , $ this , $ this ->cache ? $ this ->cache ->getStorage () : null );
591+ return new GroupedSelection ($ this ->explorer , $ this ->conventions , $ table , $ column , $ this , $ this ->cache ? $ this ->cache ->getStorage () : null );
589592 }
590593
591594
592595 protected function query (string $ query ): Nette \Database \ResultSet
593596 {
594- return $ this ->context ->queryArgs ($ query , $ this ->sqlBuilder ->getParameters ());
597+ return $ this ->explorer ->queryArgs ($ query , $ this ->sqlBuilder ->getParameters ());
595598 }
596599
597600
@@ -796,16 +799,16 @@ public function insert(iterable $data)
796799 {
797800 //should be called before query for not to spoil PDO::lastInsertId
798801 $ primarySequenceName = $ this ->getPrimarySequence ();
799- $ primaryAutoincrementKey = $ this ->context ->getStructure ()->getPrimaryAutoincrementKey ($ this ->name );
802+ $ primaryAutoincrementKey = $ this ->explorer ->getStructure ()->getPrimaryAutoincrementKey ($ this ->name );
800803
801804 if ($ data instanceof self) {
802- $ return = $ this ->context ->queryArgs ($ this ->sqlBuilder ->buildInsertQuery () . ' ' . $ data ->getSql (), $ data ->getSqlBuilder ()->getParameters ());
805+ $ return = $ this ->explorer ->queryArgs ($ this ->sqlBuilder ->buildInsertQuery () . ' ' . $ data ->getSql (), $ data ->getSqlBuilder ()->getParameters ());
803806
804807 } else {
805808 if ($ data instanceof \Traversable) {
806809 $ data = iterator_to_array ($ data );
807810 }
808- $ return = $ this ->context ->query ($ this ->sqlBuilder ->buildInsertQuery () . ' ?values ' , $ data );
811+ $ return = $ this ->explorer ->query ($ this ->sqlBuilder ->buildInsertQuery () . ' ?values ' , $ data );
809812 }
810813
811814 $ this ->loadRefCache ();
@@ -824,11 +827,11 @@ public function insert(iterable $data)
824827
825828 // First check sequence
826829 if (!empty ($ primarySequenceName ) && $ primaryAutoincrementKey ) {
827- $ primaryKey [$ primaryAutoincrementKey ] = $ this ->context ->getInsertId ($ this ->context ->getConnection ()->getSupplementalDriver ()->delimite ($ primarySequenceName ));
830+ $ primaryKey [$ primaryAutoincrementKey ] = $ this ->explorer ->getInsertId ($ this ->explorer ->getConnection ()->getSupplementalDriver ()->delimite ($ primarySequenceName ));
828831
829832 // Autoincrement primary without sequence
830833 } elseif ($ primaryAutoincrementKey ) {
831- $ primaryKey [$ primaryAutoincrementKey ] = $ this ->context ->getInsertId ($ primarySequenceName );
834+ $ primaryKey [$ primaryAutoincrementKey ] = $ this ->explorer ->getInsertId ($ primarySequenceName );
832835
833836 // Multi column primary without autoincrement
834837 } elseif (is_array ($ this ->primary )) {
@@ -885,7 +888,7 @@ public function update(iterable $data): int
885888 return 0 ;
886889 }
887890
888- return $ this ->context ->queryArgs (
891+ return $ this ->explorer ->queryArgs (
889892 $ this ->sqlBuilder ->buildUpdateQuery (),
890893 array_merge ([$ data ], $ this ->sqlBuilder ->getParameters ())
891894 )->getRowCount ();
0 commit comments