Sql CakePhp:一个模型的多个关系

Sql CakePhp:一个模型的多个关系,sql,cakephp,associations,models,has-and-belongs-to-many,Sql,Cakephp,Associations,Models,Has And Belongs To Many,我在一个模型中有两个关联的问题。。 一张小照片能让我的问题更清楚一点 对不起,我不能在这里张贴照片 所以我有可以写/拥有文章的用户。。一个用户可以写多篇文章,一篇文章只能由一个用户拥有,但有多篇 现在用户可以喜欢其他用户的文章。。。这是一种关系,属于多种关系。。我的问题是,当我创建一篇文章sql dumps时: Cannot add or update a child row: a foreign key constraint fails (`xxx`.`articles_users`,...

我在一个模型中有两个关联的问题。。 一张小照片能让我的问题更清楚一点

对不起,我不能在这里张贴照片

所以我有可以写/拥有文章的用户。。一个用户可以写多篇文章,一篇文章只能由一个用户拥有,但有多篇

现在用户可以喜欢其他用户的文章。。。这是一种关系,属于多种关系。。我的问题是,当我创建一篇文章sql dumps时:

Cannot add or update a child row: a foreign key constraint fails (`xxx`.`articles_users`,... 
因此,cake使用了错误的关系habtm而不是has many,因此使用了错误的表article_用户而不是article

我可以用正确的表编写自己的save查询,我已经尝试过了,而且效果很好,但我认为这不是最好的解决方案

有人知道更好的方法吗??谢谢

编辑:

文章模式

所有者:

public $belongsTo = array(
        'User' => array(
            'className' => 'User',
            'foreignKey' => 'user_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        )
    );
喜欢:

   public $hasAndBelongsToMany = array('User' => array( 
            'className' => 'User',
            'joinTable' => 'articles_users',
            'foreignKey' => 'article_id',
            'associationForeignKey' => 'user_id',
            'unique' => 'keepExisting',
            'conditions' => '',
            'fields' => '',
            'order' => '',
            'limit' => '',
            'offset' => '',
            'finderQuery' => '',
            'deleteQuery' => '',
            'insertQuery' => ''
        )
    );
用户模型


在用户模型中,关系名称/别名相同:Article。让他们与众不同。
根据:但是,每个型号的别名在整个应用程序中必须是唯一的。

为您的用户和文章型号共享相关型号代码$hasMany、$belongsTo、HABTM
public $hasMany = array(
    'Article' => array(
        'className' => 'Article',
        'foreignKey' => 'user_id',
        'dependent' => false,
        'conditions' => '',
        'fields' => '',
        'order' => '',
        'limit' => '',
        'offset' => '',
        'exclusive' => '',
        'finderQuery' => '',
        'counterQuery' => ''
    )
);

    public $hasAndBelongsToMany = array(
    'Article' => array(
        'className' => 'Article',
        'joinTable' => 'articles_users',
        'foreignKey' => 'user_id',
        'associationForeignKey' => 'article_id',
        'unique' => 'keepExisting',
        'conditions' => '',
        'fields' => '',
        'order' => '',
        'limit' => '',
        'offset' => '',
        'finderQuery' => '',
        'deleteQuery' => '',
        'insertQuery' => ''
    ));