<?php

namespace PluginsNameSpaces\Models;

use PluginsNameSpaces\Framework\Database\Orm\Model;

/**
 * Example model bound to the {prefix}___SNAKE_NAME___examples table.
 *
 * Demonstrates casts, mass-assignment guarding, timestamps and a
 * one-to-many relationship.
 *
 *   Example::all();
 *   Example::find($id);
 *   Example::query()->where('status', 'active')->with('items')->paginate(15);
 *   Example::create(['title' => 'Hi']);
 */
class Example extends Model
{
    /** @var string Table name (without the WordPress prefix). */
    protected static $table = '__SNAKE_NAME___examples';

    /** @var string Primary key column. */
    protected static $primaryKey = 'id';

    /** @var array Mass-assignable attributes. */
    protected $fillable = ['title', 'status', 'meta'];

    /** @var array Attribute casts. */
    protected $casts = [
        'id'     => 'int',
        'meta'   => 'array',
    ];

    /**
     * The items belonging to this example.
     *
     * @return \PluginsNameSpaces\Framework\Database\Orm\Relations\HasMany
     */
    public function items()
    {
        return $this->hasMany(ExampleItem::class, 'example_id');
    }
}
