4spacesdk/CI4OrmExtension

Error CodeIgniter\Model->__call('includeRelated', Array)

Closed this issue · 1 comments

Hi, i have this error after install OrmExtension:

CRITICAL - 2020-06-01 14:33:24 --> Call to undefined method App\Models\CampingModel::includeRelated #0 /var/www/html/meucamping/portal/app/Models/CampingModel.php(19): CodeIgniter\Model->__call('includeRelated', Array) #1 /var/www/html/meucamping/portal/app/Controllers/HomeController.php(26): App\Models\CampingModel->getDestaques() #2 /var/www/html/meucamping/portal/vendor/codeigniter4/framework/system/CodeIgniter.php(914): App\Controllers\HomeController->index() #3 /var/www/html/meucamping/portal/vendor/codeigniter4/framework/system/CodeIgniter.php(400): CodeIgniter\CodeIgniter->runController(Object(App\Controllers\HomeController)) #4 /var/www/html/meucamping/portal/vendor/codeigniter4/framework/system/CodeIgniter.php(308): CodeIgniter\CodeIgniter->handleRequest(NULL, Object(Config\Cache), false) #5 /var/www/html/meucamping/portal/public/index.php(45): CodeIgniter\CodeIgniter->run() #6 {main}

This is my code in CampingModel:

`<?php
namespace App\Models;

use CodeIgniter\Model;

class CampingModel extends Model {

protected $table = 'camping';
protected $primaryKey = 'id';
protected $returnType = 'object';

// relationship
public $hasMany = [
	PhotoModel::class
];

public function getDestaques() {
	return $this
		->includeRelated(PhotoModel::class)
		->findAll(6);
}`

This is my code in App\Config\OrmExtension.php:
`<?php

namespace Config;

class OrmExtension
{
public static $modelNamespace = ['App\Models\'];
public static $entityNamespace = ['App\Entities\'];

/*
 * Provide Namespace for Xamarin models folder
 */
public $xamarinModelsNamespace          = 'App.Models';

}`

And this is my code in App\Config\Events.php:
`<?php namespace Config;

use CodeIgniter\Events\Events;

/*


  • Application Events

  • Events allow you to tap into the execution of the program without
  • modifying or extending core files. This file provides a central
  • location to define your events, though they can always be added
  • at run-time, also, if needed.
  • You create code that can execute by subscribing to events with
  • the 'on()' method. This accepts any form of callable, including
  • Closures, that will be executed when the event is triggered.
  • Example:
  •  Events::on('create', [$myInstance, 'myMethod']);
    

*/

Events::on('pre_system', function () {
if (ENVIRONMENT !== 'testing')
{
while (\ob_get_level() > 0)
{
\ob_end_flush();
}

	\ob_start(function ($buffer) {
		return $buffer;
	});
}

/*
 * --------------------------------------------------------------------
 * Debug Toolbar Listeners.
 * --------------------------------------------------------------------
 * If you delete, they will no longer be collected.
 */
if (ENVIRONMENT !== 'production')
{
	Events::on('DBQuery', 'CodeIgniter\Debug\Toolbar\Collectors\Database::collect');
	Services::toolbar()->respond();
}

});

Events::on('pre_system', [\OrmExtension\Hooks\PreController::class, 'execute']);`

This is result of composer update:
`composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 1 update, 0 removals

  • Installing 4spacesdk/ci4debugtool (1.0.8): Downloading (100%)
  • Updating 4spacesdk/ci4ormextension (0.6 => 1.0.0-beta.23): Downloading (100%)
    Writing lock file
    Generating autoload files
    Generating autoload files`

Your model must extend OrmExtension\Extensions\Model and not CodeIgniter\Model.