Re: Associations to reduce # of queries

2007-05-09 Thread soytuny
1. Don't store your results in $this->Product. That is confusing. 2. To expose data to the view use $this->set('variable_name', $data_for_variable); 3. I have never used loadModel. Instead, at the top of the controller I would add the unassociated model to the $uses array. For example in Cat

Re: Associations to reduce # of queries

2007-05-09 Thread johnvv
Ok, I was able to get around the error messages with this: // CategoryController .. function view($id){ .. loadModel('Product'); $p = new Product(); $this->Product = $p->getProductsByCategory($id, $start, $limit, $sort); pr($this); $this->set('category', $this->Category->read()); }

Re: Associations to reduce # of queries

2007-05-09 Thread Jon Bennett
> Hmm... ok, I understand setting up the function in the Product model > to run the query but I'm confused about the CategoryController. > If I try to run: $catProds = $this->Category->Product->getCategoryProducts($categoryId); you have to traverse the associations tree back. If you're working w

Re: Associations to reduce # of queries

2007-05-09 Thread johnvv
Hmm... ok, I understand setting up the function in the Product model to run the query but I'm confused about the CategoryController. If I try to run: $catProds = $this->Product->getCategoryProducts($categoryId); I get "Undefined property: CategoryController::$Product " or if I try $catProds = $

Re: Associations to reduce # of queries

2007-05-08 Thread soytuny
I don't think you will have much luck getting cake to produce a similar query. But an easy solution is to wrap your query inside a function in your Product model. Say function getCategoryProducts($categoryId) { return $this->query(/*that query you've written*/); } Then you can use that in yo

Associations to reduce # of queries

2007-05-08 Thread johnvv
I'm to new using cake so file this question under 'newbies'... I have the following models: - Product (contains reference to manufacturer_id... and other information) - ProductImage (id,product_id,type [thumbnail,medium,large], image_url) - Manufacturer - Category - CategoryProduct (category_id,