在阅读T.Otwell关于Laravel中良好设计模式的书之后,在Laravel4中创建应用程序时,我发现自己正在为应用程序中的每个表创建存储库.
I ended up with the following table structure:
- Students: id, name
- Courses: id, name, teacher_id
- 教师:ID,姓名
- 作业(job):ID、名称、Course_id
- Scores (acts as a pivot between students and assignments): student_id, assignment_id, scores
I have repository classes with find, create, update and delete methods for all of these tables. Each repository has an Eloquent model which interacts with the database. Relationships are defined in the model per Laravel's documentation: http://laravel.com/docs/eloquent#relationships.
When creating a new course, all I do is calling the create method on the Course Repository. That course has assignments, so when creating one, I also want to create an entry in the score's table for each student in the course. I do this through the Assignment Repository. This implies the assignment repository communicates with two Eloquent models, with the Assignment and Student model.
我的问题是:由于这个应用程序的大小可能会增加,并且会引入更多的关系,与存储库中的不同Eloquent 模型通信是一种好做法,还是应该使用其他存储库(我的意思是从分配存储库中调用其他存储库)来实现这一点,还是应该在Eloquent 模型中一起完成?
Also, is it good practice to use the scores table as a pivot between assignments and students or should it be done somewhere else?