<?php

namespace Datacake\Core\ORM\WP;


use Datacake\Core\ORM\Eloquent\Model;

/**
 * Class Post
 *
 * @packageDatacake\Core\ORM\WP
 */
class Post extends Model
{

    protected $post_type = null;
    protected $primaryKey = 'ID';

    const CREATED_AT = 'post_date';
    const UPDATED_AT = 'post_modified';

    /**
     * Filter by post type
     *
     * @param $query
     * @param string $type
     *
     * @return mixed
     */
    public function scopeType($query, $type = 'post')
    {
        return $query->where('post_type', '=', $type);
    }

   
    /**
     * Get comments from the post
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function comments()
    {
        return $this->hasMany('Datacake\Core\ORM\WP\Comment', 'comment_post_ID');
    }

    /**
     * Get meta fields from the post
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function meta()
    {
        return $this->hasMany('Datacake\Core\ORM\WP\PostMeta', 'post_id');
    }
}