Zend_Db_Table joined queries vs database view

Active3 hr before
Viewed126 times

3 Answers


Make a view joining user and role tables in my database and create a new set of Zend_DbTable, Zend_DbTableRowset and Zend_DbTableRow. This way I can have specific logic in my database stack.,Make a custom join on the role table in the user table which will return an index array composed of associative array. In that case I can't call my getName() function defined in my Model_DbTable_User to build the name (first name + middle + last name). Even if I "cast" my array to a Zend_Db_Table_Rowset (or my custom table_rowset) I can't access my custom class method since I get a generic Zend_Db_Table_Row object.,I don't want to have to use the findDependentRowset that will run additionnal queries for each row that get returned. (will get problematic in data grid that display the data as many rows can be returned).,Once you've created the views, you can choose a strategy that best solves the problem. If you're creating a form that represents a single entity, then an ORM is probably a good fit. But if you're displaying large lists of data or generating reports that contain many entities then using a declarative language like SQL is probably easier and would perform better.

Current structure goes as follow

Data Access-- > Business Logic-- > Controller-- > View
load more v

See Example #28 "Removing the integrity check on Zend_Db_Table_Select to allow JOINed rows",That mean $this is quite certainly a Zend_Db_Table in your example. By default select taken from a Zend_Db_Table cannot perform joins (as they are used for Active Record operation by default).,I have faced same problem. this is because you are connecting with a database table that is not related to the specific table. So, we need to turn off the integrity test. you can view the detail solution here.,'Select query cannot join with another table '

I have two tables users and assets and foreign key is user_id. I want users detail and count of each user's asset So, I wrote query as below but not getting records. Please help me.

$users = $this - > select() -
   > from(array('u' => 'users'),
      array('firstname')) -
   > joinLeft(array('a' => 'assets'),
      'u.id = a.user_id',
      array('asset_per_user' => 'COUNT(a.id)')) -
   > group('u.id');
load more v

An inner join (sometimes called a simple join) is a join of two or more tables that returns only those rows that satisfy the join condition.,A semijoin returns rows that match an EXISTS subquery without duplicating rows from the left side of the predicate when multiple rows on the right side satisfy the criteria of the subquery.,A join is a query that combines rows from two or more tables, views, or materialized views. Oracle Database performs a join whenever multiple tables appear in the FROM clause of the query. The select list of the query can select any columns from any of these tables. If any two of these tables have a column name in common, then you must qualify all references to these columns throughout the query with table names to avoid ambiguity.,Oracle Database Data Warehousing Guide for a complete discussion of group outer joins and filling gaps in sparse data

You cannot use the (+) operator to outer-join a table to itself, although self joins are valid. For example, the following statement is not valid:

--The following statement is not valid:
   SELECT employee_id, manager_id
FROM employees
WHERE employees.manager_id(+) = employees.employee_id;

However, the following self join is valid:

SELECT e1.employee_id, e1.manager_id, e2.employee_id
FROM employees e1, employees e2
WHERE e1.manager_id(+) = e2.employee_id
ORDER BY e1.employee_id, e1.manager_id, e2.employee_id;
load more v

Other "queries-undefined" queries related to "Zend_Db_Table joined queries vs database view"