ORM module of Kohana HMVC PHP5 Framework
Questions tagged [kohana-orm]
248 questions
61
votes
12 answers
Favourite Kohana Tips & Features?
Inspired from the other community wikis, I'm interested in hearing about the lesser known Kohana tips, tricks and features.
Please, include only one tip per answer.
Add Kohana versions if necessary.
This is a community wiki.

The Pixel Developer
- 13,282
- 10
- 43
- 60
15
votes
3 answers
Kohana 3.2 ORM and PDO
I am giving Kohana a try and I was trying to use the ORM + PDO + MySQL database, and I don't seem to find an answer in google or SO.
I have both the database and ORM modules enabled, and I have set PDO as default in…

Onema
- 7,331
- 12
- 66
- 102
11
votes
3 answers
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
…

josef.van.niekerk
- 11,941
- 20
- 97
- 157
6
votes
1 answer
Is it possible to re-use a Kohana ORM query for the row count?
So I have my query as so...
$records = ORM::factory('category');
Add a WHERE clause as so...
$records = $records->where('categoryid', 'LIKE', 'aa');
Grab a count for pagination as so...
$count = $records->count_all();
And my where clause gets…

Serhiy
- 2,505
- 3
- 33
- 49
6
votes
3 answers
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 =…

Dexter
- 5,666
- 6
- 33
- 45
5
votes
1 answer
Kohana 3 ORM compares 2 columns in where clause
I need to generate query like that :
SELECT * FROM `table1` WHERE `date1` < `date2`
I can't find how to compare 2 columns in kohana ORM. Here date2 is considered as text.
$foo = ORM::factory('model1')->where('date1','<','date2');
How can I write…

Thierry R.
- 138
- 1
- 1
- 6
5
votes
2 answers
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)

leonardys
- 504
- 4
- 10
4
votes
2 answers
many-to-many relationship on kohana 3.2
I've got some trouble trying to make this work. I have 2 models, User_Pro and Category. I read the relationships documentation on kohana guide and I understand i need to define a $_has_many relationship on the User_Pro and Category models and create…

Xavier
- 53
- 1
- 4
4
votes
2 answers
MySQL - How to query items by tags, order by matched tag count
My schema looks something like this:
items ( id, title, blah )
tags (id, name )
item_tags ( item_id, tag_id )
I want to list all items, where the item's tags are "in" an array of selected tags, and then order by the number of tags that match the…

tom
- 718
- 8
- 15
4
votes
2 answers
Tables not joining in Kohana 3.1 ORM
How do I get this to work?
$stuff = ORM::factory('mytable')
->with('user')
->with('other_stuff')
->find_all();
I've got all of my relationships set up and everything seems to be working when I do other queries. However, in the query…

user256430
- 3,575
- 5
- 33
- 33
4
votes
1 answer
Kohana 3 ORM find_all() returns all rows regardless of where clause
I have one simple users table, and I want to find all users where email_notifications = 1.
Logic dictates that the following should work:
class Controller_Test extends Controller {
public function action_index()
{
$user =…

user256430
- 3,575
- 5
- 33
- 33
4
votes
1 answer
Kohana v3.1.0 ORM _ignored_columns -- now that it's gone, what should I do instead?
It seems that in v3.1.0 of Kohana's ORM that the _ignored_columns property has been removed.
What the is the recommended technique to dealing with fields that aren't in the databases? The case I have right now is password_confirm where password is a…

Darryl Hein
- 142,451
- 95
- 218
- 261
4
votes
4 answers
Helping Kohana 3 ORM to speed up a little
I noticed that Kohana 3 ORM runs a "SHOW FULL COLUMNS" for each of my models when I start using them:
SHOW FULL COLUMNS FROM `mytable`
This query might take a few clock cycles to execute (in the Kohana profiler it's actually the slowest of all…

Luke
- 20,878
- 35
- 119
- 178
4
votes
3 answers
Kohana 3 ORM as_array return array of ORM
I'm executing a simple query and want to get an array back.
Based on the ORM tutorial that comes with the Kohana 3 guide, I thought I could do the following:
ORM::factory('user')->find_all()->as_array();
But that seems to give me an array of model…

Chris J
- 131
- 2
- 2
- 4
4
votes
1 answer
Sorting by foreign table value with Kohana ORM
Is there any way to sort (or order by) in ORM by using a value from a foreign table?
Can you do something like the following:
ORM::factory("table")->order_by("table.foregin_table.column" , "ASC")
Or do you have to use some regular MySQL and join…

Navetz
- 393
- 1
- 2
- 12