Question

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.

Was it helpful?

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

OTHER TIPS

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top