kohana-orm

How do I relate tables with different foreign key names in Kohana ORM?

I'm building a Kohaha application to manage sip lines in asterisk. I'm wanting to use ORM but I'm wondering how do relate certain tables that are already well established. e.g. the table sip_lines looks like this. +--------------------+------------------+------+-----+-------------------+-----------------------------+ | Field ...

Kohana v3 ACL A2 with database support

Hi, I am using Kohana V 3.0.3. I was looking for ACL library and found from http://dev.kohanaphp.com/projects A2 Kohana's ACL module. Apparently it's found that, it manages Roles,Resources and Rules using config file and authenticate object basis. I want it to be dynamic, like Resources and Rules should be loaded from database dyn...

Kohana ORM get one record in many-to-many relationship

Hi Guys, I've got two tables (items / tags). Item has and belongs to many tags - tag has and belongs to many items. It's no problem for me to fetch all related tags like: $item = ORM::factory('item', 4); foreach($item->tags as $tag){....} But how can i fetch only one... and maybe a specific one? Thanks in advance! ...

KO 2.3.4 - Accessing validation array from callbacks in models

Hi, Apologies if this is an oversight or sheer stupidity on my part but I can't quite figure out how to access the validation array from a callback in a model (using ORM and KO 2.3.4). I want to be able to add specific error messages to the validation array if a callback returns false. e.g This register method: public function registe...

Kohana ORM Aliasing and "Trying to get property of non-object"

I have the following tables in the database: teams: id name matches: id team1_id team2_id I've defined the following ORM models in my Kohana v2.3.4 application: class Match_Model extends ORM { protected $belongs_to = array('team1_id' => 'team', 'team2_id' => 'team'); } class Team_Model extends ORM { protected $has_many = ar...

PHP: ORM framework or library that I can use with my database table structure

Hi, I was using KohanaPHP ORM but I can't use it with my database table structure. So, I need a framework or library ORM to use with it. With Kohana I need to follow a naming convention. I can't use a field name (foreign key) like 'idUnidadeMedida'. Are there any suggestions? Thank you. ...

Kohana PHP - Multiple apps with shared model

I'm using Kohana 3 to create a website that has two applications, an admin application and the actual site frontend. I have separated my folders to have the two applications separated, so the hierarchy looks as follows: /applications /admin /classes /controller /... /site /classes /control...

Kohana 3 simple relations..

I'm trying to write a very simple cms (for learning purposes) in kohana 3 web framework. I have my db schemas and i want to map it to ORM but i have problems with relations. Schemas:articles and categories One article has one category. One category might has many articles of course. I think it is has_one relationship in article table....

Kohanav3 ORM: calling where->find_all twice

When I do something like the following: $site = ORM::factory('site')->where('name', '=', 'Test Site')->find(); $users = $site->users; $deletedusers = $users->where('deleted', '=', '1')->find_all(); $nondeletedusers = $users->where('deleted', '=', '0')->find_all(); The contents of $deletedusers is correct, but the $nondeletedusers cont...

Kohana 3 ORM - grouping where conditions with parentheses

I'm trying to run a query through the ORM like this: SELECT * from table where (fname like 'string%' or lname like 'string%') AND (fname like 'string2%' or lname like 'string2%'); Here's what i have so far: $results = ORM::factory('profiles'); foreach ($strings as $string) { $result->where('fname', 'like', "$string%"); $r...

How to use database functions in Kohana 3 ORM select query

I'm using Postgres with Kohana 3's ORM module and would like to run a SELECT using a postgres function to convert values already in the database to lower case before doing the comparison. In SQL I would write: select * from accounts where lower(email) = '[email protected]'; In Kohana I would like to write something like this: $user = O...

How to delete all user roles in Kohana 3

I'm using ORM Auth module and it's difficult to figure out how to do it. I've tried this case: $user = ORM::factory('user', $id); $user->roles->delete_all(); And got error ErrorException [ Fatal Error ]: Call to undefined method Database_Query_Builder_Delete::join() However $user->roles->find_all(); gives me exactly what i want. ...

Kohana 2 ORM - created_at & updated_at

I know it's possible in KO3 via protected $_updated_column = array(' column' => 'updated_at', 'format' => 'Y-m-d H:i:s '); any way to do created_at and updated_at in the model on save (Kohana 2.3.4 ORM)? ...

Help using one model to validate another's validation process in Kohana 3.

Using KO 3.07... and ORM I have a survey model, and a choices model. The survey itself holds the question, while the choices are all the given options that people have for that survey question... (As of now, 2 choices per survey.) In my survey model, I need to validate that the actual question is within a given range of characters, an...

Kohana ORM relationships question

I have tables: users {id, name} projects {id, name} roles {id, name} projects_users {id, user_id, project_id, role_id} I have models: project { has many users through projects_users } user { has many projects through projects_users } Question: How i get user roles for one project? Or maybe i have to reconstruct my tables? Code: ...

How to create virtual properties in Kohana 3 ORM

I have a timestamp field in a model where the time is stored in UTC. I would like like to create a 'virtual' property that allows me to access the model using local time based on the timezone property also stored in the model. That is when I get the local_started_at property it reads the started_at property and adjusts the value based ...

Kohana 3 auth module, getting users with 'staff' or 'manager' role

I'm learning the framework, and now building an application using it. I need to get all users that have 'user' or 'staff' role, but I couldn't find about it on the documentation. Help anyone? (I think it's more an ORM problem the the auth module) ...

KO3: Pretend properties on a Kohana_ORM Model

Say I have a very simple model that looks like this: class Model_Person extends ORM { /* CREATE TABLE `persons` ( `id` INT PRIMARY KEY AUTO_INCREMENT, `firstname` VARCHAR(45) NOT NULL, `lastname` VARCHAR(45) NOT NULL, `date_of_birth` DATE NOT NULL, ); */ } Is there a way I can I add sort of a pretend property with...

Sorting by (order_by) foreign table value with Kohana ORM.

Is there any way to sort in orm by using a value from a forgin table? Can you do something like orm::factory("table")->order_by("table.foregin_table.column" , "ASC") or do you have to use some regular mysql and join the tables together old school? ...

Can I save new related objects via reference without copying id's manually in Kohana 3's ORM?

I have 2 objects. Player and Match. Player is a child of Match. I want to know if I can create both of these at the same time without inserting id's manually. i.e. $match = ORM::factory('match'); $player1 = ORM::factory('player'); $player2 = ORM::factory('player'); $player1->match = $match; $player2->match = $match; $match->save(); ...