Extends Selection by custom implementation

Notice: This thread is very old.
mystik
Member | 289
+
0
-

Because of chenges in new Nette (2.3) I'm not able to access connection when I got Selection instance.
I need this to determine what database is selection connected to because of syntax differences (different function names). I really don't want to fore all my model classes dependency on database Context. Not mention in one use case i connect to two different databases and I do not know from which one the Selection is from.

One possible solution is to create custom Selection inplementation which extends Nette Selection. This implementation simply adds new method which internally determine what database is used and adds correct SQL.

But I crashed in this because I need to extends both Selection and GroupedSelection. It creates parellel hierarchies.

<?php
class MySelection extends Selection {

  public function addSpecificSql() {}

}

class MyGroupedSelection extends GroupedSelection {

  public function addSpecificSql() {}

}

?>

Problem is when I do this then I cannot use type hint for places where MySelection is expected. If instead of MySelection I got MyGroupedSelection it throws Exception.

Proposed solutions:

  1. Un-deprecate getConnection in selection. Then it would be possible to use wrapper around Selection to achieve this (my solution in < 2.3)
  2. Add interfaces ISelection and IGroupedSelection so I can create my own interfaces to use in type hints.

Or is there any other way how to avoid this problem?