[Solar-svn] Revision 2799
pmjones at solarphp.com
pmjones at solarphp.com
Fri Sep 28 21:36:08 CDT 2007
branch: Solar_Model_*: [CHG] Updated to match new Solar_Sql_Model naming ('foreign_class' vice 'foreign_model').
Modified: branches/orm/Solar/Model/Areas.php
===================================================================
--- branches/orm/Solar/Model/Areas.php 2007-09-29 02:32:47 UTC (rev 2798)
+++ branches/orm/Solar/Model/Areas.php 2007-09-29 02:36:07 UTC (rev 2799)
@@ -52,7 +52,7 @@
* Relationships.
*/
$this->_hasMany('nodes', array(
- 'foreign_model' => 'nodes',
+ 'foreign_class' => 'nodes',
'foreign_key' => 'parent_id',
));
Modified: branches/orm/Solar/Model/Nodes/Blogs.php
===================================================================
--- branches/orm/Solar/Model/Nodes/Blogs.php 2007-09-29 02:32:47 UTC (rev 2798)
+++ branches/orm/Solar/Model/Nodes/Blogs.php 2007-09-29 02:36:07 UTC (rev 2799)
@@ -9,12 +9,12 @@
*/
$this->_belongsTo('area', array(
- 'foreign_model' => 'areas',
+ 'foreign_class' => 'areas',
'foreign_key' => 'area_id',
));
$this->_hasMany('comments', array(
- 'foreign_model' => 'comments',
+ 'foreign_class' => 'comments',
'foreign_key' => 'parent_id',
));
}
Modified: branches/orm/Solar/Model/Nodes/Comments.php
===================================================================
--- branches/orm/Solar/Model/Nodes/Comments.php 2007-09-29 02:32:47 UTC (rev 2798)
+++ branches/orm/Solar/Model/Nodes/Comments.php 2007-09-29 02:36:07 UTC (rev 2799)
@@ -4,7 +4,7 @@
{
parent::_setup();
$this->_belongsTo('node', array(
- 'foreign_model' => 'nodes',
+ 'foreign_class' => 'nodes',
'foreign_key' => 'parent_id', // normally node_id
));
Modified: branches/orm/Solar/Model/Nodes/Revisions.php
===================================================================
--- branches/orm/Solar/Model/Nodes/Revisions.php 2007-09-29 02:32:47 UTC (rev 2798)
+++ branches/orm/Solar/Model/Nodes/Revisions.php 2007-09-29 02:36:07 UTC (rev 2799)
@@ -9,7 +9,7 @@
* Relationships.
*/
$this->_belongsTo('node', array(
- 'foreign_model' => 'node',
+ 'foreign_class' => 'node',
'foreign_key' => 'parent_id',
));
}
Modified: branches/orm/Solar/Model/Nodes/Trackbacks.php
===================================================================
--- branches/orm/Solar/Model/Nodes/Trackbacks.php 2007-09-29 02:32:47 UTC (rev 2798)
+++ branches/orm/Solar/Model/Nodes/Trackbacks.php 2007-09-29 02:36:07 UTC (rev 2799)
@@ -4,7 +4,7 @@
{
parent::_setup();
$this->_belongsTo('node', array(
- 'foreign_model' => 'nodes',
+ 'foreign_class' => 'nodes',
'foreign_key' => 'parent_id', // normally node_id
));
Modified: branches/orm/Solar/Model/Nodes/Wikis.php
===================================================================
--- branches/orm/Solar/Model/Nodes/Wikis.php 2007-09-29 02:32:47 UTC (rev 2798)
+++ branches/orm/Solar/Model/Nodes/Wikis.php 2007-09-29 02:36:07 UTC (rev 2799)
@@ -8,13 +8,13 @@
* Relationships.
*/
$this->_hasMany('revisions', array(
- 'foreign_model' => 'revision',
+ 'foreign_class' => 'revision',
'foreign_key' => 'parent_id',
'order' => 'id DESC',
));
$this->_hasMany('comments', array(
- 'foreign_model' => 'comment',
+ 'foreign_class' => 'comment',
'foreign_key' => 'parent_id',
));
}
Modified: branches/orm/Solar/Model/Nodes.php
===================================================================
--- branches/orm/Solar/Model/Nodes.php 2007-09-29 02:32:47 UTC (rev 2798)
+++ branches/orm/Solar/Model/Nodes.php 2007-09-29 02:36:07 UTC (rev 2799)
@@ -111,7 +111,6 @@
// make sure the name is unique for its area and model
$where = array(
- 'id != :id',
'inherit = :inherit',
'area_id = :area_id',
);
@@ -129,18 +128,18 @@
* Relationships.
*/
$this->_belongsTo('area', array(
- 'foreign_model' => 'areas',
+ 'foreign_class' => 'areas',
'foreign_key' => 'area_id',
'eager' => false,
));
$this->_hasMany('taggings', array(
- 'foreign_model' => 'taggings',
+ 'foreign_class' => 'taggings',
'foreign_key' => 'node_id',
));
$this->_hasMany('tags', array(
- 'foreign_model' => 'tags',
+ 'foreign_class' => 'tags',
'through' => 'taggings',
'through_key' => 'tag_id',
));
@@ -183,7 +182,7 @@
protected function _newSelectByTags($tag_list, $params)
{
// setup
- $params = $this->_fixSelectParams($params);
+ $params = $this->fixSelectParams($params);
$select = $this->newSelect($params['eager']);
// catalog entries for joining
@@ -199,16 +198,16 @@
->from("{$this->_table_name} AS {$this->_model_name}", $params['cols'])
// join taggings on nodes
->join(
- "{$taggings['foreign_table']} AS {$taggings['foreign_alias']}",
- "{$taggings['foreign_alias']}.node_id = $native_primary"
+ "{$taggings->foreign_table} AS {$taggings->foreign_alias}",
+ "{$taggings->foreign_alias}.node_id = $native_primary"
)
// join tags on taggings
->join(
- "{$tags['foreign_table']} AS {$tags['foreign_alias']}",
- "{$tags['foreign_alias']}.id = {$taggings['foreign_alias']}.tag_id"
+ "{$tags->foreign_table} AS {$tags->foreign_alias}",
+ "{$tags->foreign_alias}.id = {$taggings->foreign_alias}.tag_id"
)
// select for the listed tags
- ->where("{$tags['foreign_alias']}.name IN (?)", $tag_list)
+ ->where("{$tags->foreign_alias}.name IN (?)", $tag_list)
// user-provided WHERE
->multiWhere($params['where'])
// group by nodes.id to collapse multiple nodes (1 for each tag)
@@ -232,7 +231,21 @@
return $this->countPages($params);
}
- $select = $this->_newSelectByTags($tag_list, $params);
- return $select->countPages('bookmarks.id');
+ // we need to select the nodes + tags as an "inner" sub-select;
+ // clear any limits on it.
+ $inner = $this->_newSelectByTags($tag_list, $params);
+ $inner->clear('limit');
+
+ // set up the outer select, which will wrap the inner sub-select
+ $outer = Solar::factory($this->_select_class, array(
+ 'sql' => $this->_sql
+ ));
+
+ // wrap the sub-select and make sure paging is correct
+ $outer->fromSelect($inner, $this->_model_name);
+ $outer->setPaging($this->_paging);
+
+ // *now* get the count of pages with the tags requested
+ return $outer->countPages("{$this->_model_name}.{$this->_primary_col}");
}
}
Modified: branches/orm/Solar/Model/Taggings.php
===================================================================
--- branches/orm/Solar/Model/Taggings.php 2007-09-29 02:32:47 UTC (rev 2798)
+++ branches/orm/Solar/Model/Taggings.php 2007-09-29 02:36:07 UTC (rev 2799)
@@ -16,12 +16,12 @@
);
$this->_belongsTo('node', array(
- 'foreign_model' => 'nodes',
+ 'foreign_class' => 'nodes',
'foreign_key' => 'node_id',
));
$this->_belongsTo('tag', array(
- 'foreign_model' => 'tags',
+ 'foreign_class' => 'tags',
'foreign_key' => 'tag_id',
));
}
Modified: branches/orm/Solar/Model/Tags.php
===================================================================
--- branches/orm/Solar/Model/Tags.php 2007-09-29 02:32:47 UTC (rev 2798)
+++ branches/orm/Solar/Model/Tags.php 2007-09-29 02:36:07 UTC (rev 2799)
@@ -38,18 +38,19 @@
* Relationships.
*/
$this->_hasMany('taggings', array(
- 'foreign_model' => 'taggings',
+ 'foreign_class' => 'taggings',
'foreign_key' => 'tag_id',
));
$this->_hasMany('nodes', array(
- 'foreign_model' => 'nodes',
+ 'foreign_class' => 'nodes',
'through' => 'taggings',
));
}
- public function fetchAllWithCount($params)
+ public function fetchAllWithCount($params = null)
{
+ $params = $this->fixSelectParams($params);
$select = $this->_newSelectWithCount($params);
return $this->_fetchAll($select, $params);
}
@@ -62,12 +63,12 @@
}
// setup
- $params = $this->_fixSelectParams($params);
+ $params = $this->fixSelectParams($params);
$select = $this->newSelect($params['eager']);
// catalog entries for joining
- $taggings = $this->_related['taggings'];
- $nodes = $this->_related['nodes'];
+ $taggings = $this->getRelated('taggings');
+ $nodes = $this->getRelated('nodes');
// primary key on this table alias; e.g., tags.id
$native_primary = "{$this->_model_name}.{$this->_primary_col}";
@@ -80,16 +81,16 @@
->from("{$this->_table_name} AS {$this->_model_name}", $params['cols'])
// join taggings on tags
->join(
- "{$taggings['foreign_table']} AS {$taggings['foreign_alias']}",
- "{$taggings['foreign_alias']}.tag_id = $native_primary"
+ "{$taggings->foreign_table} AS {$taggings->foreign_alias}",
+ "{$taggings->foreign_alias}.tag_id = $native_primary"
)
// join nodes on taggings
->join(
- "{$nodes['foreign_table']} AS {$nodes['foreign_alias']}",
- "{$nodes['foreign_alias']}.id = {$taggings['foreign_alias']}.node_id"
+ "{$nodes->foreign_table} AS {$nodes->foreign_alias}",
+ "{$nodes->foreign_alias}.id = {$taggings->foreign_alias}.node_id"
)
// select for the owner_handle
- ->where("{$nodes['foreign_alias']}.owner_handle = ?", $owner_handle)
+ ->where("{$nodes->foreign_alias}.owner_handle = ?", $owner_handle)
// group on primary key for counts
->group($native_primary)
// user-provided ORDER, paging, etc
@@ -101,19 +102,18 @@
// fetch
$select = $this->_newSelectWithCount($params);
- $select->where('nodes.owner_handle = ?', $owner_handle);
+ $select->where("{$nodes->foreign_alias}.owner_handle = ?", $owner_handle);
return $this->_fetchAll($select, $params);
}
protected function _newSelectWithCount($params)
{
- // setup
- $params = $this->_fixSelectParams($params);
+ // params should have been fixed by this point
$select = $this->newSelect($params['eager']);
// catalog entries for joining
- $taggings = $this->_related['taggings'];
- $nodes = $this->_related['nodes'];
+ $taggings = $this->getRelated('taggings');
+ $nodes = $this->getRelated('nodes');
// primary key on this table alias; e.g., tags.id
$native_primary = "{$this->_model_name}.{$this->_primary_col}";
@@ -126,13 +126,13 @@
->from("{$this->_table_name} AS {$this->_model_name}", $params['cols'])
// join taggings on tags
->join(
- "{$taggings['foreign_table']} AS {$taggings['foreign_alias']}",
- "{$taggings['foreign_alias']}.tag_id = $native_primary"
+ "{$taggings->foreign_table} AS {$taggings->foreign_alias}",
+ "{$taggings->foreign_alias}.tag_id = $native_primary"
)
// join nodes on taggings
->join(
- "{$nodes['foreign_table']} AS {$nodes['foreign_alias']}",
- "{$nodes['foreign_alias']}.id = {$taggings['foreign_alias']}.node_id"
+ "{$nodes->foreign_table} AS {$nodes->foreign_alias}",
+ "{$nodes->foreign_alias}.id = {$taggings->foreign_alias}.node_id"
)
// group on primary key for counts
->group($native_primary)
More information about the Solar-svn
mailing list