public static function getMap($current_class, $target_table, $relation = null, $join = false) { if (isset(SalamaData::$c[$relation])) { # TABLE: (possible) belongsTo (foreignKey) relation via Table; FK JOIN $target_table = $current_class; $map = self::$belongsTo; if (SalamaBuild::getRelation($relation, $target_table, 'ref')) { list($fk, $pk) = SalamaBuild::getRelation($relation, $target_table, 'both'); } # inverse belongsTo if (empty($fk)) { $map = self::$hasOne; list($pk, $fk) = SalamaBuild::getRelation($target_table, $relation, 'both'); } # check for hasMany under JOIN conditions if ($join) { if (isset(SalamaData::$rel[self::$hasMany][$target_table][$relation])) { $relation = SalamaData::$rel[self::$hasMany][$target_table][$relation][0]; $map = self::$hasMany; } } } else { # hasOne/hasMany relation (fieldname) if (isset(SalamaData::$c[$target_table][$relation])) { $field = SalamaData::$c[$target_table][$relation]; # Table.column_name (key=>val settings) if (isset($field[self::$belongsTo])) { $map = self::$belongsTo; } elseif (isset($field[self::$hasOne])) { $map = self::$hasOne; } elseif (isset($field[self::$hasMany])) { $map = self::$hasMany; } if (isset($field['foreignkey'])) { $fk = $field['foreignkey']; } elseif (isset($field[self::$through])) { # through (m:m)? list($pk, $fk) = SalamaBuild::getRelation($field[self::$through], $target_table, 'both'); } else { list($pk, $fk) = SalamaBuild::getRelation($current_class, $target_table, 'both'); } } else { # FK taken from Table we are obtaining data from; _rel[reference][target] list($pk, $fk) = SalamaBuild::getRelation($current_class, $target_table, 'both'); } } return array('map' => isset($map) ? $map : null, 'foreignkey' => isset($fk) ? $fk : null, 'localkey' => isset($pk) ? $pk : null); }