<?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/HasOne.php
 * Implements hasOne relationship
 */
class HasOne extends Relation {
	/**
	 * Retrieves the related model based on the foreign key and local key relationship.
	 *
	 * @return BaseModel|null Returns an instance of the related model if found, or null if no matching record exists.
	 */
	public function get() {
		$relatedModel = $this->getRelatedModel();

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