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 806959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:19:39+00:00 2026-05-15T00:19:39+00:00

I just started with the version 3 of the Kohana Framework. I have worked

  • 0

I just started with the version 3 of the Kohana Framework.
I have worked a little with the $_has_many etc.

Now I have the table pages. The primary key is pageID. The table has a column called parentPageID. Now I want to make a ORM model who, when accesed like this $page->parent->find() returns the page identified by parentPageID.

I have the following already:

// Settings
protected $_table_name  = 'pages';
protected $_primary_key = 'pageID';
protected $_has_one = array(
    'parent' => array(
        'model'     => 'page',
        'foreign_key'   => 'parentPageID',
    ),
);

But that does not work, it simply returns the first page from the table. Last query says this:

SELECT `pages`.* FROM `pages` ORDER BY `pages`.`pageID` ASC LIMIT 1

Does somebody know how to solve this?

I know this can: $parent = $page->parent->find($page->parentPageID); but it must be and can be cleaner (I think).

Solved, see my answer below.

  • 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-15T00:19:39+00:00Added an answer on May 15, 2026 at 12:19 am

    I solved it my self. I needed to swap the things. I explain:

    You can make a sentence like this: A page belongs to his parent page.

    So, when I thought like that I know what i did wrong.

    No I have this (what works perfectly):

    protected $_belongs_to = array
    (
        'parent' => array
        (
            'model' => 'page',
            'foreign_key' => 'parentPageID'
        )
    );
    protected $_has_many = array
    (
        'childs' => array
        (
            'model' => 'page',
            'foreign_key' => 'parentPageID',
        )
    );
    

    I can use it like this:

    $havesParent = $page->parent->loaded();
    $childs = $page->childs->find_all()->as_array();
    // ...
    

    @Stackoverflow
    Sorry I filled your database with a question I answered my self.

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

Sidebar

Related Questions

Hi I have just started using IntelliJ again and have version 9. I just
I have just started building a app using XihSolutions.DotMSN.dll version: 2.0.0.40909, My problem is
I have just started to use Apache Maven. Now I would like to make
I have just started playing with TeamCity and its great. Now I got it
I have just started to use the newest version of S#arp Architecture 1.9.5, which
I have just started writing a web application. I am using GIT for version
I just started to dig into Boost::Spirit, latest version by now -- V2.4. The
I just started using the FB Csharp SDK and installed the latest version of
Good evening, I just started playing with Microsoft.Contracts (latest version) and plugging it on
I just started playing with memcache(d) last night so I have a LOT to

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.