11.02
php
saved
lloydhome
Note
RE: Trac#633: recursive association query
RE: Trac#633: recursive association query
- suppose models User, Subarea, Area, Deal
- Area hasMany Subarea
- Subarea hasOne Area
- User hasOne Subarea
- User hasMany Deal
- Deal hasOne User
- Deal hasOne Subarea
- $this->User->findAll("Deal.Subarea.Area.name = 'SouthEast'")
- is different than
- $this->User->findAll("Subarea.Area.name = 'SouthEast'")
- so doing
- $this->User->findAll("Area.name = 'SouthEast'")
- is ambiguous (unless the association names were different but unlikely).
- But fully naming the path this way has the problem of naming in the query unless it is fully escaped in the query. The dbo should find these and escape properly.
- Then do you return all of the fields from all of the joins? We should be able to be smart enough to see what joins are needed ignoring the recursion. So recursion is set to '1' but Subarea and Area needed to be joined but this requires a bit of parsing not previously performed. A recursive descent parsing is required anyway to link up all the joins.
- The list of linked tables needs to be maintained so they are not requeried when running down the recursive levels to get data if we return the fields on the first query.
- Now if we do all this work to join and return fields and place fields in the data array based on recusion depth, why not do this in many other cases where no query is specified? Currently, $this->User->findAll() with recursive=2 invloves many separate calls that we might be able eliminate if a join is used or maybe it reduces the number by joining some and then separate queries for others.
Parsed in 0.054 seconds, using GeSHi 1.0.7.14