<?php
/**
 * RadiusBooking API Route Registrar
 *
 * This class is responsible for registering API routes dynamically with the WordPress REST API.
 * It supports CRUD operations and allows for middleware to be applied globally or per route.
 *
 * @package RadiusTheme\RadiusBooking\Core\Api\Routes
 */

namespace RadiusTheme\RadiusBooking\Core\ORM\Relations;

use RadiusTheme\RadiusBooking\Abstracts\BaseModel;
if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}
/**
 * Core/ORM/Relations/BelongsTo.php
 * Implements belongsTo relationship
 */
class BelongsTo extends Relation {
	/**
	 * Retrieves the associated related model based on the defined local key and foreign key relationship.
	 *
	 * @return BaseModel|null Returns the first instance of the related model if found, or null if no match exists.
	 */
	public function get() {
		$relatedModel = $this->getRelatedModel();

		return $relatedModel->where( $this->localKey, $this->parent->{$this->foreignKey} )->first();
	}
}
