| 45 | | |
|---|
| 46 | | // done! |
|---|
| 47 | | return; |
|---|
| 48 | | } |
|---|
| 49 | | |
|---|
| 50 | | // more-complex "has many through" relationship. |
|---|
| 51 | | // join the native table to the mapping table. |
|---|
| 52 | | $join_table = "{$this->through_table} AS {$this->through_alias}"; |
|---|
| 53 | | $join_where = "{$this->native_alias}.{$this->native_col} = " |
|---|
| 54 | | . "{$this->through_alias}.{$this->through_native_col}"; |
|---|
| 55 | | |
|---|
| 56 | | $select->leftJoin($join_table, $join_where); |
|---|
| 57 | | |
|---|
| 58 | | // join the mapping table to the foreign table. |
|---|
| 59 | | $join_table = "{$this->foreign_table} AS {$this->foreign_alias}"; |
|---|
| 60 | | $join_where = "{$this->through_alias}.{$this->through_foreign_col} = " |
|---|
| 61 | | . "{$this->foreign_alias}.{$this->foreign_col}"; |
|---|
| 62 | | |
|---|
| 63 | | $select->leftJoin($join_table, $join_where); |
|---|
| | 61 | |
|---|
| | 62 | // honor foreign inheritance |
|---|
| | 63 | if ($this->foreign_inherit_col) { |
|---|
| | 64 | $select->where( |
|---|
| | 65 | "{$this->foreign_alias}.{$this->foreign_inherit_col} = ?", |
|---|
| | 66 | $this->foreign_inherit_val |
|---|
| | 67 | ); |
|---|
| | 68 | } |
|---|
| | 69 | } |
|---|
| 95 | | // less-complex "has many" relationship. |
|---|
| 96 | | return parent::modSelectCountPages($select); |
|---|
| 97 | | } |
|---|
| 98 | | |
|---|
| 99 | | // more-complex "has many through" relationship. |
|---|
| 100 | | // join the native table to the mapping table. |
|---|
| 101 | | $join_table = "{$this->through_table} AS {$this->through_alias}"; |
|---|
| 102 | | $join_where = "{$this->native_alias}.{$this->native_col} = " |
|---|
| 103 | | . "{$this->through_alias}.{$this->through_native_col}"; |
|---|
| 104 | | |
|---|
| 105 | | $select->leftJoin($join_table, $join_where); |
|---|
| 106 | | |
|---|
| 107 | | // join the mapping table to the foreign table. |
|---|
| 108 | | $join_table = "{$this->foreign_table} AS {$this->foreign_alias}"; |
|---|
| 109 | | $join_where = "{$this->through_alias}.{$this->through_foreign_col} = " |
|---|
| 110 | | . "{$this->foreign_alias}.{$this->foreign_col}"; |
|---|
| 111 | | |
|---|
| 112 | | $select->leftJoin($join_table, $join_where); |
|---|
| 113 | | |
|---|
| 114 | | // honor foreign inheritance |
|---|
| 115 | | if ($this->foreign_inherit_col) { |
|---|
| 116 | | $select->where( |
|---|
| 117 | | "{$this->foreign_alias}.{$this->foreign_inherit_col} = ?", |
|---|
| 118 | | $this->foreign_inherit_val |
|---|
| 119 | | ); |
|---|
| 120 | | } |
|---|
| | 93 | // less-complex "has many" relationship. use the standard parent |
|---|
| | 94 | // method. |
|---|
| | 95 | parent::modSelectCountPages($select); |
|---|
| | 96 | } else { |
|---|
| | 97 | // more-complex "has many through" relationship. |
|---|
| | 98 | // join the native table to the mapping table. |
|---|
| | 99 | $table = "{$this->through_table} AS {$this->through_alias}"; |
|---|
| | 100 | $where = "{$this->native_alias}.{$this->native_col} = " |
|---|
| | 101 | . "{$this->through_alias}.{$this->through_native_col}"; |
|---|
| | 102 | |
|---|
| | 103 | $select->leftJoin($table, $where); |
|---|
| | 104 | |
|---|
| | 105 | // join the mapping table to the foreign table. |
|---|
| | 106 | $table = "{$this->foreign_table} AS {$this->foreign_alias}"; |
|---|
| | 107 | $where = "{$this->through_alias}.{$this->through_foreign_col} = " |
|---|
| | 108 | . "{$this->foreign_alias}.{$this->foreign_col}"; |
|---|
| | 109 | |
|---|
| | 110 | $select->leftJoin($table, $where); |
|---|
| | 111 | |
|---|
| | 112 | // honor foreign inheritance |
|---|
| | 113 | if ($this->foreign_inherit_col) { |
|---|
| | 114 | $select->where( |
|---|
| | 115 | "{$this->foreign_alias}.{$this->foreign_inherit_col} = ?", |
|---|
| | 116 | $this->foreign_inherit_val |
|---|
| | 117 | ); |
|---|
| | 118 | } |
|---|
| | 119 | } |
|---|
| | 120 | |
|---|
| | 121 | // make the rows distinct, so we only get one row regardless of |
|---|
| | 122 | // the number of related rows (since we're not selecting cols). |
|---|
| | 123 | $select->distinct(true); |
|---|