<?php

namespace CliqThemes\ORM\Entities;

use CliqThemes\ORM\Model;

/**
 * ORM model representing the wp_term_relationships table.
 */
class TermRelationship extends Model
{
    protected string $table = 'term_relationships';

    protected string $primaryKey = 'object_id';

    protected array $fillable = [
        'object_id',
        'term_taxonomy_id',
        'term_order',
    ];

    protected bool $timestamps = false;

    /**
     * Relationship to the taxonomy entry connected to the object.
     */
    public function taxonomy()
    {
        return $this->belongsTo(TermTaxonomy::class, 'term_taxonomy_id', 'term_taxonomy_id');
    }

    /**
     * Relationship to the post assigned to the taxonomy entry.
     */
    public function post()
    {
        return $this->belongsTo(Post::class, 'object_id', 'ID');
    }
}

