We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

find model with join and access to getter method

Dear All,

I have a requirement where I want to find records with join from multiple tables and then I want to access property value via getter method

public function initialize() {
    $this->belongsTo('state_id', 'States', 'state_id', array('alias' => 'States',
        "foreignKey" => array("allowNulls" => FALSE, "message" => "{~Invalid %s|State~}"))
    );
}

public function getStateName() {
    //////// some customized logic
    return strtoupper($this->statename." blah blah....");
}

$stations = Stations::query()
            ->columns(['States.state_name', 'station_name'])
            ->join('States')
            ->execute();
    echo $stations[1]->state_name;
    die;

so if State name is "Moscow" in database,then above code must print "MOSCOW blah blah...."

Note : Because I do not want to execute queries multiple times through chaining method (for statename) as I have to extract heavy data.

Since you are selecting certain columns phalcon will return Row object which doesn't know anything about your models. Just return full object or do proper select in sql.