One
If the column is creator, then the relationship should have a different name (this is why we tend to have the _id suffix). I would suggest using creator_id as the column name, and creator as the relationship name - it stays close to convention:
// Article.php
public function creator()
{
return $this->belongsTo(User::class); // creator_id is inferred from the relationship name
}
Two
If you have a hasOne relationship, then you should be getting zero or one Gallery instances, not galleries. Notwithstanding, you can traverse the relationship once they have been correctly setup. An Article hasOne Gallery; a Gallery belongsTo a creator (User), so that same suggestion applies as before for the column name on galleries table
// Gallery.php
public function creator()
{
return $this->belongsTo(User::class); // creator_id is inferred from the relationship name
}
Then, whenever you have an Article instance, you can traverse the relationships (so long as gallery and creator will return an object!
$article->gallery->creator->name;
Three Don't know yii, but you can eager-load the relations so they are nested in the parent object:
$article = Article::with('gallery')->find(1);
// or use dot syntax to eager-load nested relations
$article = Article::with('gallery.creator')->find(1);
// or multiple relations:
$article = Article::with(['creator', 'gallery.creator')->find(1);
Four Without seeing the code that generates the response. it is impossible to assist
Five
So long as the relationships exist, and the records are associated, then $article->creator->profile->moderator->username will work, but that is a long chain; it might be better to find a way to simplify the call.