0

Currently I am writing a website using Kohana framework 3.3. Today, I wanted to create subpage where user would be able to browse news, however I encountered a small problem with Kohana ORM.

I would like to retrieve only a dozen / several dozen characters from a text field, because loading the entire field would be a significant waste of server resources.

Does anyone know how I can achieve the same effect as in those cases?

Thanks in advance for your answers.

Community
  • 1
  • 1
sky
  • 3
  • 2

3 Answers3

0

Looking at the code behind ORM, it seems it's not possible to load a partial model. You may have to use the Database_Query_Builder class, combined with DB::expr to achieve this.

tmuguet
  • 1,165
  • 6
  • 10
0

This isn't possible with the ORM class. You can build your own query with Kohana's own query builder and the object can be returned as an ORM-model, therefore you fill in your ORM model name (e.g. 'my_orm_model') in the as_object function.

Combining one of your suggested links with Kohana's own Query builder you would get something like this.

DB::Query(Database::SELECT,"SELECT LEFT(field, 40) AS excerpt FROM table(s) WHERE ...")->as_object('my_orm_class')->execute();
Daan
  • 7,685
  • 5
  • 43
  • 52
0

ORM was designed for working with a whole records (queries like SELECT * FROM ...). You can store fulltext values in separated (MyISAM) table, so your ORM models will skip that field.

biakaveron
  • 5,493
  • 1
  • 16
  • 20
  • Thank you for you answer. It's a pity that there is no ORM skip() function, which could ignore (unselect) specified fields or retrieve only specified amount of data. – sky Jan 12 '13 at 02:03