Welcome Guest, Not a member yet? Register   Sign In
Entities returned by Model missing parent methods?
#1
Question 
(This post was last modified: 11-09-2020, 04:54 PM by schertt.)

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
Reply
#2

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

(This post was last modified: 11-13-2020, 12:08 PM by schertt.)

(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.
Reply
#4

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

(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


Reply




Theme © iAndrew 2016 - Forum software by © MyBB