bcosca / fatfree

A powerful yet easy-to-use PHP micro-framework designed to help you build dynamic and robust Web applications - fast!
2.66k stars 446 forks source link

Feature Request: $mapper->reset() to optionally also clear the virtual fields #667

Open ethanpil opened 10 years ago

ethanpil commented 10 years ago

I propose we add an optional parameter to $mapper->reset() that will also remove all of the vfields.

 function $mapper->reset($vfields = False)  {

Per https://groups.google.com/forum/#!topic/f3-framework/RQA-NOcuBWk

jimymodi commented 9 years ago

@ethanpil What do you suggest the default behavior should be $mapper->reset($vfields = False) { or $mapper->reset($vfields = True) { . So by default virtual fields should be wiped out or done only on request.

ethanpil commented 9 years ago

I think we will do best to keep the default function the same to ensure backwards compatibility.

Rayne commented 9 years ago

@jimymodi created PR https://github.com/bcosca/fatfree/pull/835 for this issue.

Rayne commented 9 years ago

I don't like the idea to add virtual fields and then drop them later to reuse the object. This could cause unexpected side effects. At least the default value $vfields = false is reasonable.

xfra35 commented 7 years ago

I don't think it should belong to reset(), because this method is used to reset the cursor, not to modify the mapper structure.

Why not adding an adhoc() method, so we can loop and clear all adhoc fields?

foreach ($mapper->adhoc() as $key)
  $mapper->clear($key);

This solution also allows to filter adhoc fields out:

foreach ($mapper->adhoc() as $key)
  if (preg_match('/^total_/',$key))
    $mapper->clear($key);
ethanpil commented 7 years ago

How about $mapper->wipe() or $mapper->reboot() or something similar which can be used to simply restore the mapper to brand new status.