We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Newbie questions about models

do u have to have a model for every table in your database? if not how do use say 5 different tables within one model? for example, say i have a model called Baseball.php and i want to use 5 different tables in my model. so say i have thses tables: baseball_teams baseball_cities baseball_mascots baseball_leagues baseball_positions

how can i use the one model to run find on each table?

thanks in advance for the help



8.6k

You should have one model for each table. The model IS the table, so to speak.



2.6k

A model is a entity.

Because a baseballteam is not the same as a baseballmascot you don't persist them in the same table. So why would you use a single entity to store two different entities? In Phalcon a model is use to store the data it retrieved from the database in a logical way. Unlike some frameworks which use a model as database access layer and query other tables from a single table.

Thanks for the answers so say I have a database with 100 different tables. I will need a Model for each one?

Also, is there a db adpater for MicroSoft SQL databases???