gabordemooij / redbean

ORM layer that creates models, config and database on the fly
https://www.redbeanphp.com
2.31k stars 279 forks source link

$bean->export() vs R::exportAll() #702

Closed Lynesth closed 5 years ago

Lynesth commented 5 years ago

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 for ownlists and sharedlists of your bean and will retrieve all of those as well. That's the part that takes time. Note that if you set $parents to TRUE it will not retrieve the ownlists and sharedlists 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 ?

marios88 commented 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

gabordemooij commented 5 years ago

Sorry for the long delay, I had to make money to keep the boat floating.

Lynesth commented 5 years ago

@gabordemooij We currently have:

Proposal from @marios88 was to add those 2 functions:

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.

marios88 commented 5 years ago

@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

gabordemooij commented 5 years ago

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.

marios88 commented 5 years ago

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!

gabordemooij commented 5 years ago

Okay fine, thanks. FYI - Manual is available as open source file: https://github.com/gabordemooij/redbean/blob/manual/redbean_manual.html