Retrieving Only Some Fields in RedBean

I use ORB RedBean to write code, and I was wondering if I can load / extract only some fields from the db table. I know there is a load method, but it gives the whole table as a bean. I want to get only some fields?

Heh, when I wrote it, I began to wonder if this is against the RedBean (or ORM) pattern, because getting only some values ​​will lead to the creation of invalid (only with some values) object / bean? I wanted to do some lazy loading of values ​​... maybe there is another ORM (as simple as RedBean :) to achieve this?

+6
source share
1 answer

It makes no sense to load only some fields from the record:

  • By choosing fewer fields, you will not reduce the number of queries
  • This will not reduce the amount of data that needs to be transferred (this is more related to the number of rows)

In addition, RedBeanPHP already lazy loads all relational fields, so there is no need for this guide. If you are only interested in using one cell:

R::getCell("select title from document where id = 1"); 

Or just grab some fields from a record:

 R::getRow("select id,title from document where... "); 

These functions return records, not beans; this is the fastest way to handle simple fields and strings.

Hope this answer helps ...

+3
source

Source: https://habr.com/ru/post/891641/


All Articles