CodeIgniter Forums
Entities returned by Model missing parent methods? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Entities returned by Model missing parent methods? (/showthread.php?tid=77949)



Entities returned by Model missing parent methods? - schertt - 11-09-2020

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


RE: Entities returned by Model missing parent methods? - paulbalandan - 11-13-2020

This can be because in your BaseEntity constructor you are not explicitly calling parent::__construct.


RE: Entities returned by Model missing parent methods? - schertt - 11-13-2020

(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.


RE: Entities returned by Model missing parent methods? - paulbalandan - 11-15-2020

Can you post the constructor part of both your BaseEntity and sample child Entity?


RE: Entities returned by Model missing parent methods? - schertt - 11-15-2020

(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