Retrieving only some fields in RedBean
I'm using RedBean ORM to write some code and I was wondering if i can load/retrive only some fields from db table. I know there is a load method but it gives whole table as bean. I wish to get only some fields?
Heh, when i wrote it, I started wondering if it's not against RedBean pattern(or ORM), because getting only some values will create invalid(with only 开发者_StackOverflow中文版some values) object/bean? I wanted to make some lazy loading of values... maybe there is some other ORM(as easy as RedBean:) to achive this?
It does not make sense to load just some fields from a record:
- By selecting less fields you won't decrease the number of queries
- It wont decrease the amount of data that needs to be transferred (this is more related to the number of rows)
Also, RedBeanPHP already lazy-loads all relational fields, so there is no need to do this manual. If you are interested in only a single cell use:
R::getCell("select title from document where id = 1");
Or to 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 deal with simple fields and rows.
Hopefully this answer helps...
精彩评论