CodeIgniter Forums

Full Version: Entities returned by Model missing parent methods?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

I have a series of Models that use corresponding Entities as their $returnTypes. The corresponding Entities all inherit from a BaseEntity class which in turn inherits from CI's Entity class. 

In the course of my unit testing, I'm noticing that when one of my Models returns query results in Entity form, those Entity objects are missing the public methods of their upper-most parent class (the CI Entity). The child methods are not overriding any of the parent's methods. 

If I directly construct an Entity within the Model itself, those inherited methods are there. What am I missing here?

CI version 4.0.4
This can be because in your BaseEntity constructor you are not explicitly calling parent::__construct.
(11-13-2020, 07:32 AM)paulbalandan Wrote: [ -> ]This can be because in your BaseEntity constructor you are not explicitly calling parent::__construct.

Yes, I am explicitly calling the parent constructor all the way up. To that effect, I have the properties defined in CI's Entity... but not the methods, which is why this is so confusing to me. You'd think it would be all or nothing.
Can you post the constructor part of both your BaseEntity and sample child Entity?
(11-15-2020, 11:58 AM)paulbalandan Wrote: [ -> ]Can you post the constructor part of both your BaseEntity and sample child Entity?

Sure. This is the BaseEntity:


PHP Code:
<?php

namespace App\Entities;
use 
CodeIgniter\Entity;

class 
BaseEntity extends Entity {

  public function __construct(array $data null)
  {
    parent::__construct($data);
  }

  //Class methods




And my entity (this is where I can't access the method's defined by CodeIgniter's Entity class):

PHP Code:
<?php

namespace App\Entities;

class 
Destination extends BaseEntity {

  public function __construct(array $data null)
  {
    parent::__construct($data);
  }

  //Class methods