开发者

Cakephp paginator sort method with a habtm relation question

开发者 https://www.devze.com 2022-12-18 00:16 出处:网络
Here\'s an example... I\'m using a table to manage all of my Statuses with the tree behavio开发者_开发技巧r. I have a Book model which has a status for it\'s condition and one for it\'s availability.

Here's an example...

I'm using a table to manage all of my Statuses with the tree behavio开发者_开发技巧r. 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
                    )

            )

    )


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)

0

精彩评论

暂无评论...
验证码 换一张
取 消