我遇到以下情况的问题:
用户表
id, profile_id, name, created, modified
个人资料表
id, first_name, last_name, gender
企业表
id, name, created, modified
我有一个多对多的关系表,可以将profiles
链接到businesses
:businesses_profiles
id, business_id, profile_id, created, modified
当我尝试创建新业务时,我想将直接登录的用户个人资料ID链接到我要创建的业务。
在我的profileTable
中,我已经在initialize()
中添加了:
$this->belongsToMany('Businesses', [
'alias' => 'Businesses',
'foreignKey' => 'profile_id',
'targetForeignKey' => 'business_id',
'joinTable' => 'businesses_profiles'
]);
在我的businessesTable
中,我还使用了initialize()
方法:
$this->belongsToMany('Profiles', [
'alias' => 'Profiles',
'foreignKey' => 'business_id',
'targetForeignKey' => 'profile_id',
'joinTable' => 'businesses_profiles'
]);
在每个实体Business
和Profile
中,我分别放在正确的上下文中:
protected $_accessible = [
'*' => true,
'id' => false,
'businesses' => true,
'_joinData' => true
];
和:
protected $_accessible = [
'name' => true,
'slug' => true,
'active' => true,
'hash' => true,
'data' => true,
'approved' => true,
'created' => true,
'modified' => true,
'profiles' => true,
'_joinData' => true
];
保存到businesses_profiles
表中没有任何作用。
在此先感谢您的帮助, 最好,
洛朗。
答案 0 :(得分:0)
非常感谢您的帮助。我已经通过使用CakePHP提供的link()方法找到了解决方案。
如果可以帮助其他人,我将在这里分享我的添加功能:
# Max pool size
match = re.search('Max pool size : (\d+)', out)
if match:
stats['Max pool size'] = int(match.group(1))
self.checks_logger.debug('{"name": "passenger-status", "protocol_version": "1", "integration_version": "1.0.0", "metrics": [{ "event_type": "PassengerSample", "Max pool size": "%s",' % stats['Max pool size'])
# App groups
match = re.search('App groups : (\d+)', out)
if match:
stats['App groups'] = int(match.group(1))
self.checks_logger.debug('"App groups": "%s",' %
stats['App groups'])
# Processes
match = re.search('Processes : (\d+)', out)
if match:
stats['Processes'] = int(match.group(1))
self.checks_logger.debug('"Processes": "%s",' %
stats['Processes'])
# Requests in top-level queue
match = re.search('Requests in top-level queue : (\d+)', out)
if match:
stats['Requests in top-level queue'] = int(match.group(1))
self.checks_logger.debug('"Requests in top-level queue": "%s",' %
stats['Requests in top-level queue'])
# Requests in queue
match = re.search('Requests in queue: (\d+)', out)
if match:
stats['Requests in queue'] = int(match.group(1))
self.checks_logger.debug('"Requests in queue": "%s"}]}' %
stats['Requests in queue'])
return stats
def run(self):
stats = {}
stats.update(self.get_passenger_status())
return stats
if __name__ == "__main__":
import logging
logger = logging.getLogger("Passenger")
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler())
passenger = Passenger(None, logger, None)
passenger.run()