What is the difference between table, Entity and behavior in the context of the Model?
While Table
is responsible for accessing and representing a collection of objects, a Entity represents a unique object of this collection.
The behavior
, as its literal translation says, it is a behavior that can be extended to your Model
, attributing common behaviors to other models. It is similar to Traits
.
In which class should I put this code snippet?
As per its own documentation says:
In Cakephp your application domain model is divided into 2 types of
main objects. The first ones are repositories (repositories) or
table Objects (table objects). These objects provide access to
data collections. They allow you to save new records,
modify/delete existing ones, define relationships, and
perform mass operations. The second type of objects are the entities
(entities). Entities represent individual records and allow the
you define line/record level behavior and
functionalities.
Exemplifying:
namespace App\Model\Modulo;
use Cake\ORM\TableRegistry;
class ModuloTable extends Table
{
public getAllModuloAcao($idModulo)
{
$modulo = TableRegistry::get('Modulo');
return $modulo ->find()
->select(['Modulo.Id_Modulo', 'Modulo.Nome_Modulo'])
->where(['Modulo.Id_Modulo' => $idModulo])
->contain(['Acao']);
}
}