CakePHP Twitter-clone: Can't get follow-system to work

前端 未结 1 765
时光取名叫无心
时光取名叫无心 2021-01-17 04:14

Sorry for the non-descript title, but I\'m not sure how to phrase it. Currently, I am trying my hand at developing a Twitter clone with cakePHP, since I\'m new to web progr

相关标签:
1条回答
  • 2021-01-17 04:40
    app/models/user.php
    
    class User extends AppModel{
          var $name = 'User';
    
          var $hasAndBelongsToMany = array(
                'Follower' => array(
                      'className'             => 'Follower',
                      'joinTable'             => 'user_users',
                      'foreignKey'            => 'user_id',
                      'associationForeignKey' => 'child_user_id'
                )
          )
    }
    
    app/models/follower.php
    
    class Follower extends AppModel{
          var $name     = 'Follower';
          var $useTable = 'users';
    }
    

    You will have to make a table user_users with the fields user_id and child_user_id. child_user_id would be the follower ID, you could name it follower id if you want but it might be confusing if you need to make a similar relation in the future.

    Try it out.

    0 讨论(0)
提交回复
热议问题