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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:28:26+00:00 2026-06-08T11:28:26+00:00

I have two tables named utilities and types that i am trying to access

  • 0

I have two tables named utilities and types that i am trying to access the other fields within types from the utilities view. e.g; $utilities->type->type;

Utilities would have_one type
and type would belong_to utility right?

This is how i have it currently, and rather than referencing utilities.type_id its setting the key as utilities.id. As a result its pulling different types for each row, even though they are all of the same type.

enter image description here

How should i lay my models relationships out using Kohana 3.2 ORM.

Utilities

<?php
class Model_Utility extends ORM {
    protected $_has_one = array(
        'type' => array(
            'model' => 'type',
            'foreign_key' => 'type_id',
        ),
    );

Table Structure

+---------------+--------------+------+-----+---------+----------------+
| Field         | Type         | Null | Key | Default | Extra          |
+---------------+--------------+------+-----+---------+----------------+
| id            | int(11)      | NO   | PRI | NULL    | auto_increment |
| utility_name  | varchar(255) | NO   |     | NULL    |                |
| type_id       | int(11)      | NO   |     | NULL    |                |
| contact_name  | varchar(255) | NO   |     | NULL    |                |
| contact_email | varchar(255) | NO   |     | NULL    |                |
| contact_phone | varchar(255) | NO   |     | NULL    |                |
+---------------+--------------+------+-----+---------+----------------+

Types

class Model_Type extends ORM {
    protected $_belongs_to = array(
        'utility' => array(
        )
    );

Table Structure

+---------+--------------+------+-----+---------+----------------+
| Field   | Type         | Null | Key | Default | Extra          |
+---------+--------------+------+-----+---------+----------------+
| type_id | int(11)      | NO   | PRI | NULL    | auto_increment |
| type    | varchar(255) | NO   |     | NULL    |                |
+---------+--------------+------+-----+---------+----------------+
  • 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-06-08T11:28:29+00:00Added an answer on June 8, 2026 at 11:28 am

    Utility belongs_to Type (utilities has a type_id key), and Type has_many utilities.

    PS. Also you need to define a PK name for types table ($_primary_key property).

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

Sidebar

Related Questions

I'm trying to group by categories; let's say that I have two tables named
I have a LinkTable named: BlogsBlogPosts that relates two other tables named: Blogs and
So I have two tables. Table 1 is named 'appointment' with the following fields:
I have two tables as following table one named tbooking having column fields as
So I have two tables that have a layout like (but not named): Table
I have two MS access tables in my asp.net application (named categories & books
I have two tables table1 and table2 each having a column named email along
I have two tables, both named as say, Employee in two different schema HR
I have two tables, named t_master and t_detail. The data in the t_detail table
I have two tables, one that contains nodes and second that contains the relationships

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.