Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Unable to get relations working, even in same namespace
  • Hello,

    I am new to FuelPHP and am trying to get model relationships working.

    Here are my models:

    member.php

    namespace Model;
    class Member extends \Orm\Model
    {
        protected static $_properties = array(
        );
       
        protected static $_primary_key = array('cid');
       
            protected static $_belongs_to = array(
                                  'artcc' => array(
                                           'key_from' => 'artcc_id',
                                           'model_to' => '/Model/Artcc',
                                           'key_to'   => 'id',
                                           'cascade_save' => true,
                                           'cascade_delete' => false,
    ),
                               );
    }



    artcc.php

    namespace Model;

    class Artcc extends \Orm\Model
    {
        protected static $_properties = array(
            ),
        );
       
        protected static $_has_many = array('members' => array(
                                       'key_from' => 'id',
                                       'model_to' => 'Member',
                                       'key_to'   => 'artcc_id',
                                       'cascade_save' => true,
                                       'cascade_delete' => false,
                                       )

    );
    }



    When try to call a query on Member i am recieving the error:

    Fuel\Core\FuelException [ Error ]: Related model not found by Belongs_To relation "artcc": /Model/Artcc

    Any help would be appreciated.  I have run out of ideas on my own

  • HarroHarro
    Accepted Answer
    in PHP, class names in strings are always relative to global, they are not aware of the current namespace.
    Also, the namespace separator is a backslash and not a slash, and you don't start with one.

    So the only correct model references are:

    'Model\Artcc' and 'Model\Member'
  • Thank you, I was beating my head on the wall trying to figure that out.
  • PHP is a bit quirky when it comes to namespaces.

    You might want to read http://php.net/manual/en/language.namespaces.php to get up to speed.

Howdy, Stranger!

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

In this Discussion