Tuesday, December 30, 2008

Re: Order associated data

Hi, thank you for the advice - the first one works fine, but the
second one doesn't.

I've added it to the top of the Product model, just below the $name
variable, like so:

var $name = 'Product';
var $order = 'Product.title ASC';

Any idea?

On Dec 30, 10:04 pm, Adam Royle <a...@sleekgeek.com.au> wrote:
> Yes, you've got the categories/products thing set up as I would do it.
>
> With ordering, you can do it both ways:
>
> 1) Just for this association - use the 'order' key when setting up the
> association in categories model... eg.
>
> http://book.cakephp.org/view/78/Associations-Linking-Models-Together#...
>
> 2) Globally - add it into the products model.
>
> var $order = 'Product.name DESC';
>
> Cheers,
> Adam
>
> On Dec 31, 7:31 am, Daniel <theworldof...@gmail.com> wrote:
>
> > Hi, me again, I hope you don't mind me coming back with another
> > question.
>
> > I'm not sure if I'm going about this the best way or not, so some
> > general advice would be handy.
>
> > I've got two models: Category and Product, Product belongs to
> > Category, with Category having many Product (with me so far?).
>
> > I'm using the view function within the Categories controller to list
> > the products displayed within that category. I'm using the read()
> > function to pull the data from the Category model, which of course is
> > pulling with it data from the associated Product model - which I'm
> > then just using a simple foreach ($category['Product'] as $product) {}
> > to display within the view.
>
> > Two questions - first, is this the best way of displaying products
> > within a specific category.
>
> > Second - is there anyway to change the order of the $category
> > ['Product'] array, so that it's ordered by a field other than the id.
>
> > Thank you
>
> > - Daniel

--~--~---------~--~----~------------~-------~--~----~
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+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: