Example #1
0
function getAutoJoins($foreignKeys, $columns)
{
    $output = [""];
    $output[] = <<<HTML
        'belongsTo'   => [
HTML;
    foreach ($foreignKeys as $meta) {
        $displayField = getDisplayColumn($columns[$meta->referenced_table_name]);
        $shortName = preg_replace('/_id$/', '', $meta->column_name);
        $alias = Inflector::classify($shortName);
        $aliasPadded = str_pad("'{$alias}'", 20, ' ');
        $output[] = <<<HTML
            {$aliasPadded} => ['{$meta->referenced_table_name}', '{$meta->column_name}', '{$alias}.{$displayField} AS {$shortName}'],
HTML;
    }
    $output[] = <<<HTML
        ],

HTML;
    return implode("\n", $output);
}
 /**
  * Load a model
  *
  * @param string      $table_name
  * @param AbstractPdo $connection
  * @return $this
  */
 public static function loadTable($table_name, AbstractPdo $connection = null)
 {
     $model_name = Inflector::classify($table_name);
     Assert($model_name)->notEmpty("Could not resolve model name from table name.");
     return static::loadModel($model_name, $connection);
 }