TIP: Use Markdown or, <pre> for multi line code blocks / <code> for inline code.
These forums are read-only and for archival purposes only!
Please join our new forums at discourse.kohanaframework.org
ORM model with properties from another table
  • Hello.

    I have two tables: orders and order_props. Second table collects some order properties and has fields: order_id, code, value. Example:

    (1, 'phone', '9999999999') for order with id=1
    (2, 'phone', '8888888888') for order with id=2
    (2, 'contact_name', 'John Doe') for order with id=2

    I want to operate in my Order model with order property codes like with table fields:

    echo $order->phone;
    $order->contact_name = 'John Smith';
    $orders = ORM::factory('order')->select('created_at', 'phone', 'contcat_name')->find_all(); // 'created_at' - is the orders table field, but 'phone' and 'contact_name' are "codes" of properties in order_props table
    $orders = ORM::factory('order')->where('phone', '=', '9999999999')->find_all();

    So, for first and second I can write getter and setter methods, it's clear. But how can I organize routine for methods like select(), where(), values() etc? Maybe I can use some special Kohana possibilities for this situation or there are any modules which will help me?

  • ->select()->join()->where help you :)

  • Can you write an example? I can't do that for several property codes. How do you see the select() method code, for example, for this situation:

    $orders = ORM::factory('order')->select('created_at', 'phone', 'contact_name')->find_all(); // Two joins for two codes?


  • Alright, I've write routine for where(), get(), join_props() (instead of select() because native select() can't get a list of columns in params). Now remains only set() and values(). Please, answer for another question: How can I get in model class the list of joined tables (aliases)? I need to check if table was already joined in my where() and join_props() methods (to not to duplicate joining). I was surprised that Kohana ORM doesn't check it itself. Now I just collecting an array of aliases in model property, but I think there is another way to get this.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion