I am new to Kohana framework. I am trying to use ORM module in Kohana.
My impression is that I have to create a model for each table I have.
Then only I could access the tables via those modules.
Is this correct? Can anyone explain the best practices about creating models for database access using ORM in Kohana?
Thanks in advance
Poomalairaj
When we talk about Kohana and ORM, yes, you pretty much need what we call an entity, or a model that will represent that table. That is the most common and recommended way to have your domain specified.
Remember that the concept of model in Kohana doesn’t match the general concept out there. You can have a model that is kinda like a business logic entity, that doesn’t have anything to do with the database.
To exemplify my answer, if you had a simple post application, like twitter or whatever, you would have something like this:
Kohana’s ORM will also understand if you create your models like this:
Since it works most generally with conventions over configurations.
With that domain specified, you can access some user’s posts like this:
And a post user (author) like this:
Hope that can clarify your mind!