关于如何在cakepp中定义此模型/关系的建议


Advice on how to define this model/relationship in cakephp

我是MVC框架的新手,我在思考如何在模型中准确定义MVC框架时遇到了一些问题。

`UserA` purposes `Offer1`
`UserB` sees and accepts `Offer1`
`Offer` is now complete

我最初在不同的表中有两组用户,但这意味着要做很多额外的工作,因为我认为可能有更简单的方法。

您将有三个表。如果您遵循CakePHP表命名约定,您可能会将它们称为usersoffers_usersoffers。在这种情况下,您可能希望使用hasAndBelongsToMany关系(HABTM)。的基本示例

class User extends AppModel {
    public $hasAndBelongsToMany = array(
        'Offer' =>
            array(
                'className' => 'Offer',
                'joinTable' => 'offers_users',
                'foreignKey' => 'user_id',
                'associationForeignKey' => 'offer_id',
                'unique' => false,
                'conditions' => '',
                'fields' => '',
                'order' => '',
                'limit' => '',
                'offset' => '',
                'finderQuery' => '',
                'with' => ''
            )
    );
}