finder with associated model
sergiomeza opened this issue · 1 comments
sergiomeza commented
Hi, i'm trying to display some data from a model that is associated, for example:
$reports = $this->Reports->find('all'); $reports->contain(['Users']);
but the data is not displayed, there is a way i can archieve this?
Thanks
josegonzalez commented
If you want to set related data in the csv, you'll need to use the _extract
variable, like so:
public function export() {
$posts = $this->Post->find('all');
$_serialize = 'posts';
$_header = ['Post ID', 'Title', 'Created'];
$_extract = ['Post.id', 'Post.title', 'Post.created'];
$this->viewClass = 'CsvView.Csv';
$this->set(compact('posts', '_serialize', '_header', '_extract'));
}
Checkout our readme for more details.