Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recreate RecordSet from Records #1193

Closed
alexbowers-tecmark opened this issue Jun 9, 2015 · 1 comment
Closed

Recreate RecordSet from Records #1193

alexbowers-tecmark opened this issue Jun 9, 2015 · 1 comment

Comments

@alexbowers-tecmark
Copy link

I am looking through the Records but cannot see anyway to recreate a record set from an array of records.

My use case is that I need to get 100 results from the database, but also require all of the information on the page itself (from all results). It sounds weird, but it is needed.

Anyway, the issue currently is that running the same query twice (once wiht, and once without the limit) is pointless, since i have to get all the results anyway, so getting the same results once and then using lithium to limit would be good. Once i get the results out I can convert the object to array (using RecordSet::toArray(), but I cannot find a way to do Records::toSet() or anything like that.

All of the rest of the code expects lithium recordset objects, so getting it back to a recordset is required.

Is there a way to do it?

@nateabele
Copy link
Member

There is, and while it's not quite as simple as passing in an array, if you're on PHP 7, you can still do it in one line using generator delegation. Basically, you need to wrap your Record array in an iterator, and pass it like so: new RecordSet(['result' => $iterator]).

Hope that helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants