On Wed, Jul 25, 2012 at 6:04 PM, baur79 <[email protected]> wrote:
> i have model "Report" with table "reports"
> it contain report of last month. (50 000 records every month)
>
> how can implement archive the data in another table with the same structure
> and logic.
> and manipulate reading in Model.
>
> in my controller i want to ("DRY"):
>
> function index() {
> $reports = $this->Report->find('all');
> $this->set('report', $reports);
> }
>
> function archive()
> //do some manipulation
> //$this->Report->table = "reportarchives"
>
> $reports = $this->Report->find('all');
> //but query from "archived" table
> $this->set('report', $reports);
> $this->render('index')
> }
>
> please give some suggestions

You could change your find query to only search for records created in
the last however long you want to look at.

Instead of
$this->Report->find('all')
do something like
$this->Report->find('all', 'conditions' => array('created' <
strtotime('one month ago')))

Then in the archive query
$this->Report->find('all', 'conditions' => array('created' >
strtotime('one month ago')))

If you are returning 50,000 reports, you should think about pagination
or limiting the returned array in some way.

Mike.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to