I have three models (with controllers):
- Product: Id, Title, Type_id
- Type: Id, Description
- ProductItem: Id, Product_id, Size, Sold_time

Relationships:
- Product: belongsTo(Type), hasMany(ProductItem)
- Type: hasMany(Product)
- ProductItem: belongsTo(Product)

Example:
- Product:
  1; 'Star Jeans 502', 4
  (...)

- Type:
  4; 'Trousers'
  (...)

- ProductItem:
  7; 1; 'S', NULL
  8; 1; 'S', NULL
  9; 1; 'S', NULL
  10; 1; 'M', NULL
  11; 1; 'M', NULL
  12; 1; 'L', NULL
  (...)

Now, I'd like to fetch the in such way:
Description, Type, Size, Count
Star Jeans 502, 'Trousers', 'S', 3
Star Jeans 502, 'Trousers', 'M', 2
Star Jeans 502, 'Trousers', 'L', 1

The sql query should look like this:
select Product.Title, Type.Description, ProductItem.Size,
COUNT(ProductItem.*)
left join Type on Product.Type_id = Type.id left join ProductItem on
ProductItem.Product_id = Product.id
group by Product.Id, ProductItem.Size

Is it correct?

I want to make such sql in cakephp in automagicalled way using find in
ProductItem controller. Unfortunately it does not work. I tried find
with parameter: field => (Product.Title, Type.Description,
ProductItem.Size, COUNT(ProductItem.*)) and group => (Product.Id,
ProductItem.Size), but cake doesn't want to put join on ProductType.

I think that cake builds joins only for tables in relations with
current model (ProductItem), and does not look deeper -
"belongsTo(Type)" is defined in Product model.

How to solve this problem?

Kind regards,
T.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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