Hello, I can't update the property of a model if previously I access a related model via that property
Let me explain: I'm trying to update $plan_id, but If previously I access to the related Model "Plan" via the property that connects both models (by this way: $subscription->plan->category_id), that property ($plan_id) doesn't update.
If I don't get the related property value ($subscription->plan->category_id), the property I'm trying to change ($plan_id) updates correctly.
This is the code
class Subscription extends \Phalcon\Mvc\Model
{
public $plan_id;
public function initialize()
{
$this->belongsTo('plan_id', '\Plan', 'id', ['alias' => 'plan']);
}
public function changeSubscriptionPlan($user, $newPlan)
{
$subscription = new Subscription();
$subscription = $subscription->findFirstByUserId($user->id);
if($subscription->plan->category_id == 1)
{
$subscription->plan_id = $newPlan->id;
$currentSubscription->save();
}
}
}
Also I have tried get the messages, and no errors occurs
if (!$subscription->save()) {
foreach ($subscription->getMessages() as $message) {
$this->getDI()
->getFlash()
->error($message);
}
}
Am I doing anything wrong?