public function findBelongsToMany($model, array $associations)
{
$schema = $model->schema();
$tableName = $schema->name();
$foreignKey = $this->_modelKey($tableName);
$tables = $this->listAll();
foreach ($tables as $otherTableName) {
$assocTable = null;
$offset = strpos($otherTableName, $tableName . '_');
$otherOffset = strpos($otherTableName, '_' . $tableName);
if ($offset !== false) {
$assocTable = substr($otherTableName, strlen($tableName . '_'));
} elseif ($otherOffset !== false) {
$assocTable = substr($otherTableName, 0, $otherOffset);
}
if ($assocTable && in_array($assocTable, $tables)) {
$habtmName = $this->_camelize($assocTable);
$assoc = ['alias' => $habtmName, 'foreignKey' => $foreignKey, 'targetForeignKey' => $this->_modelKey($habtmName), 'joinTable' => $otherTableName];
if ($assoc && $this->plugin) {
$assoc['className'] = $this->plugin . '.' . $assoc['alias'];
}
$associations['belongsToMany'][] = $assoc;
}
}
return $associations;
}