tags:

views:

105

answers:

1

Hi,

Here's an example...

I'm using a table to manage all of my Statuses with the tree behavior. I have a Book model which has a status for it's condition and one for it's availability. So the Book model HABTM Statuses even thought it can only have one condition and one availability.

Is there a way to use the $paginator->sort('Condition', '?') with a HABTM ? I would like to sort the title from the array below.

This is what $this->data is giving me :

[Status] => Array
    (
        [0] => Array
            (
                [id] => 2
                [parent_id] => 1
                [lft] => 2
                [rght] => 3
                [title] => Mint
                [created] => 2010-01-18 16:20:54
                [modified] => 2010-01-18 16:20:54
                [active] => 1
                [BooksStatus] => Array
                    (
                        [id] => 7
                        [book_id] => 3
                        [status_id] => 2
                    )

            )

    )
A: 

i would use 2 x belongsTo with different names.

$belongsTo = array(
  'BookStatus' => array(
    'className' => 'Status',
    'foreignKey' => 'book_status_id'
  ),
  'BookCondition' => array(
    'className' => 'Status',
    'foreignKey' => 'book_condition_id'
  )
)

dont know how this would then fit into your tree strut

if that doesnt work then Try $paginator->sort('Condition', 'BooksStatus.status_id'); you will need to make sure the query used to retrieve the above does a join(unBind/bind on the fly)

Yash
I'll go with your first suggestion for now. Thanks.
Sabourinov