Tony Mucci

Photo by Joshua Hoehne on Unsplash

THE ISSUE

I came across another Segmentation Fault error when trying to run this code:

$example = ExampleModel::findFirst(CONDITIONS_EXAMPLE_HERE)$related_model = $example->getExampleModelName([
'conditions'=>'zip_code=?1',
'bind'=>[1=>90210]
]);

THE SOLUTION

In Phalcon 4, it seems that you are unable to use indexed bind parameters and instead have to use named parameters. The following code should work for you:

$example = ExampleModel::findFirst(CONDITIONS_EXAMPLE_HERE)$related_model = $example->getExampleModelName([
'conditions'=>'zip_code=:namedBindParameterHere:',
'bind'=>['namedBindParameterHere'=>90210]
]);

Happy Coding!

--

--

Brett Jordan

The Issue

This is a quick post that will save you a ton of time trying to figure out what is going on.

When I was trying to pull some records from the model, I came across this error. The reason this is happening, is because you cannot use a magic getter method on the model that has been set to hasMany, because you are returning a result set that is an array of objects instead of simply an object as you would

The Solution

Change from this:

$model = ExampleModel::find();
$records = $model->getRelatedModel();

To this:

$model = ExampleModel::find();
$records = [];
foreach($model as $result){
$records[] = $result->getRelatedModel();
}

Then you should be good to go.

Happy Coding!

--

--

Tony Mucci

Tony Mucci

Founder of My Company Tools • Co-Founder/Former CTO of Dree • Co-Founder of Eklect Enterprises. Opinions on this blog are my own.