Skip to content

Instantly share code, notes, and snippets.

@kidsil
Created February 17, 2013 22:44
Show Gist options
  • Save kidsil/4973878 to your computer and use it in GitHub Desktop.
Save kidsil/4973878 to your computer and use it in GitHub Desktop.
Yii Model function for getting a name of a table by the relation field
public function get_name_by_relation_field($field) {
$relations = $this->relations();
$obj_name = NULL;
foreach($relations as $relation) {
if (isset($relation[2]) && $relation[2] == $field) {
$obj_name = isset($relation[1])?$relation[1]:NULL;
break;
}
}
return $obj_name;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment