Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7633425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:52:46+00:00 2026-05-31T06:52:46+00:00

I am new to Kohana framework. I am trying to use ORM module in

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T06:52:47+00:00Added an answer on May 31, 2026 at 6:52 am

    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:

    class Model_User extends ORM {
        protected $_table_name = 'user';
    
        protected $_primary_key = 'id';
    
        protected $_has_many = array('posts' => array());
    }
    
    class Model_Post extends ORM {
        protected $_table_name = 'post';
    
        protected $_primary_key = 'id';
    
        protected $_belongs_to = array('user' => array());
    }
    

    Kohana’s ORM will also understand if you create your models like this:

    class Model_User extends ORM {
        protected $_has_many = array('posts' => array());
    }
    
    class Model_Post extends ORM {
        protected $_belongs_to = array('user' => array());
    }
    

    Since it works most generally with conventions over configurations.

    With that domain specified, you can access some user’s posts like this:

    $user->posts
    

    And a post user (author) like this:

    $post->user
    

    Hope that can clarify your mind!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to learn the framework kohana. I have defined a new controller under
I'm trying to get to grips with Kohana framework for a new project. I
everybody! I have a new question about Kohana 3, or rather about a module
I'm completely new to this framework and I'm trying to find some sample CRUD
I'm using Postgres with Kohana 3's ORM module and would like to run a
I have: brand new clean copy of Kohana 2.3.4 (tried 2.4 RC1 also), a
When I try to make a new instance of the Auth-module object (Auth::factory()), Kohana
I'm using Kohana framework for my project development, I need to introduce new rules
I'm using PHP, and the Kohana framework, but that should be peripheral to this
I have a Kohana framework which is building ExtJS objects in one view, which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.