What is the difference between table, entity, and behavior in the Model context?
While Table
is responsible for accessing and representing a collection of objects, a Entity represents a singular object in this collection.
The behavior
, as its literal translation says, is behavior that can be extended to its Model
, assigning it behaviors common to other models. It's similar to Traits
.
In which class should I place this code snippet?
According to documentation says:
In CakePHP your application domain model is divided into 2 types of
main objects. The first are repositories (repositories) or
table objects. These objects provide access to
collections of data. They allow you to save new records,
modify / delete existing ones, define relationships, and
perform bulk operations. The second type of objects are entities
(entities). Entities represent individual records and allow the
you define row / 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']);
}
}