I have a slight workaround at the moment... I'm converting the area geometry
box to a text field and then performing the search
    $area = $this->Property->Seller->Agency->Channel->Area->find('first',
array(
      'conditions'  => array('Area.id' => $areaId),
      'fields'      => 'AsText(ExteriorRing(`Area`.`area_box`)) as polygon,
Country.name, Area.*',
    ));

then

    $this->paginate['conditions'] = array('MBRContains('
.$area[0]['polygon'] . ',`Location`.`location_point`)');
    $data = $this->paginate('Property');

But ideally it would be better to perform just one query instead of two...

On Mon, Aug 31, 2009 at 10:28 AM, Bryan Paddock <bryanpadd...@gmail.com>wrote:

> Hi there,
> No, properties do not have an associated area ID. Properties are located
> via their location_id.
>
> Area ID's are used in another portion of the site but in this case it is
> necessary to do a search on area's instead of locations.
>
> Lemme give the full picture to explain it more...
>
> Properties are located by a location ID pointing to a location table which
> has the geomeotric points store in it. Those are single addresses of each
> property.
> Now agencies can request "channels" where they can purchase different
> suburbs. Those suburbs are stored in the areas table and assigned to each
> channel via a join areas_channels.
>
> What I need to accomplish now is I need to be able to search for all
> properties that belong to an agencies channel that are in the channel's
> areas they have purchased. Hence the area not being directly related to the
> properties.
>
> I can't assign an area_id to a property as the area has nothing to do with
> the property.
>
> I'm thinking I may need to do some custom sql magic here....
>
>
> On Fri, Aug 28, 2009 at 5:22 PM, brian <bally.z...@gmail.com> wrote:
>
>>
>> - What I need to do now is to fetch all the properties which are
>> inside a certain area id.
>>
>> Property belongsTo Area. That is, the properties table should have an
>> area_id column.
>>
>> On Fri, Aug 28, 2009 at 7:02 AM, Bryan Paddock<bryanpadd...@gmail.com>
>> wrote:
>> > Hey all,
>> > I'm trying to execute a query including a table which is not related.
>> I'm
>> > not sure how I can go about doing this...
>> > 3 models in question:
>> > property (which has a location_id field)
>> > location (which has a location_point field stored as geometry point)
>> > area (which has an area_box field stored as a polygon)
>> > The location table is used to store single one to one locations for the
>> > properties. The area table is used to store suburbs etc for another part
>> of
>> > the site.
>> > What I need to do now is to fetch all the properties which are inside a
>> > certain area id. Sounds simple enough but I just cant figure it out.
>> Area
>> > has no relation to property and should not.
>> > The query would be something like this (I'm just writing out what the
>> sql
>> > should look like... I'm not using raw sql in my cake app)
>> > select
>> >   p.*,
>> >   a.*,
>> >   l.*
>> > from
>> >   properties p,
>> >   areas a
>> > left join
>> >   location l
>> > on
>> >   p.location_id = l.id
>> > where
>> >   a.id = 5
>> > and
>> >   MBRContains(a.area_box, l.location_point)
>> > so bascially fetch all properties where it's associated
>> > locations.location_point is inside a specific unassociated
>> areas.area_box
>> > identified by its areas.id.
>> > In my property query conditions I have set array('Area.id' => 5) but
>> because
>> > it is not a directly related model cake isn't including that table in
>> the
>> > query so its failing with an "unknown table Area"...
>> > Even if I add "Area.area_box" to the 'fields' array for the paginator it
>> > still doesn't know to fetch info from the area table.
>> > How do I tell cakephp to include an unrelated table into the query? var
>> > $uses = array('Area') was useless....
>> > >
>> >
>>
>> >>
>>
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to