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 with specific columns parameter doesn't work with relational model

Hi, I want to use specific column when using find().

in this case find with specific columns parameter doesn't work with relational model. but if I comment //$parameters['columns'] it works.

error

Notice: Undefined property: Phalcon\Mvc\Model\Row::$provinces

mycontroller

$parameters['columns'] = "id_product";    //it works fine, if i comment this line    
$products = new \App\Models\Products();
$prd = $products::findFirst($parameters);        
print_r($prd->provinces->province_name);die;

my model

public function initialize(){
    $this->belongsTo('product_state', 'App\Models\CountryProvinces', 'province_id', array('alias' => 'Provinces'));
}


98.9k

When you set the 'columns' parameter it returns an incomplete object, this is mentioned in the docs: https://docs.phalcon.io/en/latest/reference/models.html#finding-records

An incomplete object is a partial representation of the model with writing and other features not available due to possible missing data to perform these operations.