Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Cannot find has_many and belongs_to in sub-folder
  • model/calendaritem.php
    namespace Model;

    class Calendaritem extends \Orm\Model
    {

        protected static $_belongs_to = array(
            'calendaritem_category' => array(
                'model_to' => 'Model\\Calendaritem\\Category',
                'key_from' => 'calendaritem_category_id'
            )
        );

        protected static $_has_many = array(
            'schedules' => array(
                'model_to' => 'Model\\Calendar\\Schedule'
            )
        );
    }

    model/calendaritem/category.php
    namespace Model\Calendaritem;

    class Category extends \Orm\Model
    {
        protected static $_table_name = 'calendaritem_categories';
    }

    model/calendar/schedule.php
    namespace Model\Calendar;

    class Schedule extends \Orm\Model
    {
        protected static $_table_name = 'calendar_schedules';

        protected static $_belongs_to = array(
            'calendaritem' => array(
                'model_to' => 'Model\\CalendarItem',
            )
        );

        protected static $_has_many = array(
            'visits' => array(
                'model_to' => 'Model\\VisitLog',
                'key_to' => 'calendar_schedule_id'
            )
        );
    }

    model/visitlog.php
    namespace Model;

    class Visitlog extends App
    {
        protected static $_belongs_to = array(
            'schedule' => array(
                'model_to' => 'Model\Calendar\Schedule',
                'key_from' => 'calendar_schedule_id'
            )
        );
    }

    controller/visits.php
    namespace Controller;

    use Model\Visitlog;

    class Visits extends App
    {
        public function get_index($id = 'all')
        {
            $options = array(
                'limit' => 20,
                'related' => array(
                    'schedule' => array(
                        'related' => array(
                            'calendaritem' => array(
                                'related' => array(
    //                                'calendaritem_category'
                                )
                            )
                        )
                    )
                )
            );

            $result = Visitlog::find($id, $options);
        }
    }

    controller/calendaritems.php
    namespace Controller;

    use Model\Calendaritem;

    class Calendaritems extends App
    {
        public function get_index($id = 'all')
        {
            $options = array(
                'related' => array(
                    'calendaritem_category',
                    'schedules' => array(
                        'related' => array(
                            'visits'
                        )
                    )
                )
            );

            $result = Calendaritem::find($id, $options);
        }
    }

    calendaritem_category in visits controller cannot be found
    calendaritem_category & schedules in calendaritems cannot be found

    I'm using PHP 7.1/7.4
    FuelPHP 1.9
  • rrlledorrlledo
    Accepted Answer
    nm.
    The Observer Typing I created caused the issue.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion