orm: cycle\ORM\Exception\TransactionException Transaction can't be finished. Some relations can't be resolved: Update `product` - tax_rate (Cycle\ORM\Relation\BelongsTo)🐛

No duplicates 🥲.

  • I have searched for a similar issue in our bug tracker and didn’t find any solutions.

What happened?

Ubuntu 22.04 LTS Testing and Wampserver 3.2.9 Testing Above error common to both Windows and Ubuntu Apache2 using fork rossaddison/yii-invoice. Event: A new product, not used in any quote, or invoice, when tax_rate_id BelongsTo dropdown edited and saved. Also if the product’s family group BelongsTo relation changes, and is saved, same error occurs.

This error occurs when the record is edited, not created.

This error did not occur when I was using annotations instead of the current Atributes. This issue is similar to issue #329

Here is the entity that is being used:

<?php

declare(strict_types=1);

namespace App\Invoice\Entity;

use Cycle\Annotated\Annotation\Column;
use Cycle\Annotated\Annotation\Entity;
use App\Invoice\Entity\Family;
use App\Invoice\Entity\TaxRate;
use App\Invoice\Entity\Unit;
use Cycle\Annotated\Annotation\Relation\BelongsTo;

#[Entity(repository: \App\Invoice\Product\ProductRepository::class)]
class Product
{
    #[Column(type: 'primary')]
    private ?int $id = null;
        
    #[Column(type: 'text', nullable: true)]
    private ?string $product_sku = '';
    
    #[Column(type: 'text', nullable: true)]
    private ?string $product_name = '';
    
    #[Column(type: 'longText', nullable: false)]
    private ?string $product_description = '';
        
    #[Column(type: 'decimal(20,2)', nullable: true)]
    private ?float $product_price = null;
    
    #[Column(type: 'decimal(20,2)', nullable: true)]
    private ?float $purchase_price = null;
    
    #[Column(type: 'text', nullable: true)]
    private ?string $provider_name = '';
    
    #[BelongsTo(target:Family::class, nullable: false, fkAction: "NO ACTION")]
    private ?Family $family = null;        
    #[Column(type: 'integer(11)', nullable: true)]
    private ?int $family_id = null;
    
    // A product has to have a tax rate before it can be created even if it is a zero tax rate    
    #[BelongsTo(target:TaxRate::class, nullable: false, fkAction: "NO ACTION")]
    private ?TaxRate $tax_rate = null;    
    #[Column(type: 'integer(11)', nullable: false)]
    private ?int $tax_rate_id = null;
        
    #[BelongsTo(target:Unit::class, nullable: false, fkAction: "NO ACTION")]
    private ?Unit $unit = null;    
    #[Column(type: 'integer(11)', nullable: true)]
    private ?int $unit_id = null;
    
    #[Column(type: 'integer(11)', nullable: true)]
    private ?int $product_tariff = null;
    
    public function __construct(
        string $product_sku = '',
        string $product_name = '',
        string $product_description = '',
        float $product_price = null,
        float $purchase_price = null,
        string $provider_name = '',
        int $product_tariff = null,
        int $tax_rate_id = null,
        int $family_id = null,
        int $unit_id = null            
    )
    {
        $this->product_sku = $product_sku;  
        $this->product_name = $product_name;
        $this->product_description = $product_description;
        $this->product_price = $product_price;
        $this->purchase_price = $purchase_price;
        $this->provider_name = $provider_name;
        $this->product_tariff = $product_tariff;
        $this->tax_rate_id = $tax_rate_id;
        $this->family_id = $family_id;
        $this->unit_id = $unit_id;
    }
    //relation $family
    public function getFamily(): ?Family
    {
        return $this->family;
    }
    //relation $tax_rate
    public function getTaxrate(): ?TaxRate
    {
        return $this->tax_rate;
    }
    //relation $unit
    public function getUnit(): ?Unit
    {
        return $this->unit;
    }    
    
    public function getProduct_id(): ?string
    {
        return (string)$this->id;
    }
    
    public function setFamily_id(int $family_id): void
    {
        $this->family_id = $family_id;
    }
    
    public function getProduct_sku(): string
    {
        return $this->product_sku;
    }
    
    public function setProduct_sku(string $product_sku): void
    {
        $this->product_sku = $product_sku;
    }
    
    public function getProduct_name(): string
    {
        return $this->product_name;
    }
    
    public function setProduct_name(string $product_name): void
    {
        $this->product_name = $product_name;
    }
    
    public function getProduct_description(): string
    {
        return $this->product_description;
    }
    
    public function setProduct_description(string $product_description): void
    {
        $this->product_description = $product_description;
    }

    public function getProduct_price(): float
    {
        return $this->product_price;
    }
    
    public function setProduct_price(float $product_price): void
    {
        $this->product_price = $product_price;
    }
    
    public function getPurchase_price(): float
    {
        return $this->purchase_price;
    }
    
    public function setPurchase_price(float $purchase_price): void
    {
        $this->purchase_price = $purchase_price;
    }
    
    public function getProvider_name(): string
    {
        return $this->provider_name;
    }
    
    public function setProvider_name(string $provider_name): void
    {
        $this->provider_name = $provider_name;
    }

    public function setTax_rate_id(int $tax_rate_id): void
    {
        $this->tax_rate_id = $tax_rate_id;
    }

    public function getTax_rate_id(): ?int
    {
        return $this->tax_rate_id;
    }

    public function setUnit_id(int $unit_id): void
    {
        $this->unit_id = $unit_id;
    }

    public function getUnit_id(): ?int
    {
        return $this->unit_id;
    }

    public function getFamily_id(): ?int
    {
        return $this->family_id;
    }
    
    public function getProduct_tariff(): int
    {
        return $this->product_tariff;
    }

    public function setProduct_tariff(int $product_tariff): void
    {
        $this->product_tariff = $product_tariff;
    }
}

Version

ORM 2.0.0 
Ubuntu PHP 8.1.2, Wampserver PHP 8.1.7

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 36 (12 by maintainers)

Most upvoted comments

Ok the relations are saving now but new items added are experiencing an error. This is not going to be a quick solution. I have decided to create two separate functions in the service. One for adding and one for editing. This has solved my problem.

I will leave this open for a while just in case. Nevertheless, thanks a million for your help roxblnfk. Thank you for your willingness and determination.

Sorry for being pedantic / picky/ fussy but I think you have a typo in your comment:

it has TaxRate parent with id=1 and tax_rate_id=2

these should be <=> swopped.