Closed Lynesth closed 5 years ago
My proposal would be
a new $bean->exportAll()
that behaves like R::exportAll()
and R::export()
that behaves like $bean->export()
and also accepts arrays of beans
Also i suggest that the manual is updated to show the difference of function and highlight the potential performance hit of using R::exportAll()
https://redbeanphp.com/index.php?p=/import_and_export
Sorry for the long delay, I had to make money to keep the boat floating.
The manual will be shared soon.
$bean->exportAll() - I don't understand the difference, the fact that it's called R::exportAll() highlights the fact that it's a 'heavier', DB-related operation than just a $bean->export(). Or would you like to have a $bean->exportAll() that just exports the entire bean without loading anything? (would that not make it more confusing?)
@gabordemooij We currently have:
$bean->export()
which transform the beans in an array and can lookup linked beans in the database using the $parents
arguments but does not load own/shared lists.R::exportAll()
which accepts a bean or an array of beans. It duplicate each of them (which loads all their own/shared lists from database), then $bean->export()
each of them and returns an array of exported beans.Proposal from @marios88 was to add those 2 functions:
$bean->exportAll()
which would behave as R::exportAll()
(as in loading own/shared lists).R::export()
which would simply be the same as R::beansToArray()
with added parameters (ie. $parents
)I guess we could also have only two functions (one for the Facade and one as a bean method) and have them load own/shared lists based on an argument.
@Lynesth summed up my thoughts clearly!
I guess we could also have only two functions (one for the Facade and one as a bean method) and have them load own/shared lists based on an argument.
Won't that break bc? Sounds better in the long run thought
From an architectural point of view $bean->exportAll() would be a disaster because it requires all kinds of different tools like the Duplication Manager. R::export() would not be a problem though, although I prefer to simply add the parameters to beansToArray().
I am not for breaking backward compatibility. RedBeanPHP is very strong and unique in remaining backward compatibility and is even used on servers with PHP versions as old as 5.2! Also, every time in the past (around 3.0) I was breaking BC I got a shit storm of e-mails from people I've never heard of before that suddenly complained about RB not being compatible anymore. So I rather go against the mainstream here (it's trendy to break everything with every new release I believe these days) and keep everything BC until a new version of PHP makes it impossible.
That sounds like a lot of work for a convenience feature. I'm happy with highlighting the difference in the manual
keep everything BC
One of the main reasons i choose redbean was this!
Okay fine, thanks. FYI - Manual is available as open source file: https://github.com/gabordemooij/redbean/blob/manual/redbean_manual.html
Ok so I think the issue here is that export and exportAll are not doing the same thing.
The first one (
$bean->export()
) will simply take your bean as you give it and transform it in an array. The only thing it can lookup in the database while doing so are linked beans (columns ending in_id
) by using the$parents
argument.R::exportAll()
on the other hand will look through the database, searching forownlists
andsharedlists
of your bean and will retrieve all of those as well. That's the part that takes time. Note that if you set$parents
toTRUE
it will not retrieve theownlists
andsharedlists
of the linked beans.The real question now is, should we make them behave the same way ? Do we add another argument to retrieve those lists or not ?