Search code examples
phpmysqlormkohanachop

kohana orm retrieve only specified amount of characters from text column


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.


Solution

  • 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();