• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Model(s) for one business logic with few database tables

I use CodeIgniter 4 and I really like its Model class with all CRUD helpers.

My problem is I don't know how to design model(s) for business logic that uses multiple database tables. Let's say I want to handle meetings - each having a list of subjects to discuss. My database tables look like this (simplified):
CREATE TABLE meetings (
  id int(11) NOT NULL,
  date date NOT NULL,
  moderator varchar(128),
CREATE TABLE meeting_subjects (
  id int(11) NOT NULL,
  meeting_id int(11) NOT NULL,
  order int(11) NOT NULL,
  subject varchar(128) NOT NULL,

This would be very convenient to have two models like this:
PHP Code:
class MeetingsModel extends Model
    protected $table 'meetings';
    protected $primaryKey 'id';
    protected $allowedFields = [ 'date''moderator' ];

    public function insertMeeting($data$subjects)
        $subjectsModel = new MeetingSubjectsModel();

        /* Simplified insert code */
        /* TODO: set "meeting_id" */
MeetingSubjectsModel extends Model
    protected $table 'meeting_subjects';
    protected $primaryKey 'id';
    protected $allowedFields = [ 'meeting_id''order''subject' ];

As far as I understand some people find above an anemic domain model anti-pattern and they claim it should not be used. Single business logic (e.g. handling meetings) should be implemented with a single model.

Do you have any suggestions on how to handle such cases in a clean way and without re-implementing code that Model already provices?

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.