Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fields from HasMany Relationship #1

Closed
srmcatee opened this issue Sep 5, 2011 · 4 comments
Closed

Fields from HasMany Relationship #1

srmcatee opened this issue Sep 5, 2011 · 4 comments

Comments

@srmcatee
Copy link

srmcatee commented Sep 5, 2011

Is it in tthe roadmap to add field values from the hasmany or manymany relationship?

@nyeholt
Copy link
Owner

nyeholt commented Sep 5, 2011

It's something that would be nice - for the moment, if you're wanting fields from a relationship, you need to create your own AdvancedReport (or DataObjectReport) subclass and manually add in the fields the user can select by

  • Override getReportableFields() to add in the field value the user can select
  • Override getDataObjects() to provide your own logic for selecting the data objects to include in the report.

@srmcatee
Copy link
Author

Thank you for your assistance.

I've started building my own obeject. Everything looks good but when
I go to run preview on the report I get this error:

error_log(/var/log/silverstripe): failed to open stream: Is a directory
error_log([22-Sep-2011 06:28:48] Error at
advancedreports/code/dataobjects/AdvancedReport.php line 359: Uncaught
Exception: Abstract method called; please implement getDataObjects()
(http://localhost/hiho2/admin/advanced-reports/DirectoryReport/14/preview)
,3,/var/log/silverstripe,)
Line 57 of LogFileWriter.php

I've modified permissions on /var/log/silverstripe to 777. I've also
chown and chgrp to www-data. Nothing fixes it.

Can you advise what advanced report is trying to do here?

Thank you.

Steve

Quoting nyeholt
reply@reply.github.com:

It's something that would be nice - for the moment, if you're
wanting fields from a relationship, you need to create your own
AdvancedReport (or DataObjectReport) subclass and manually add in
the fields the user can select by

  • Override getReportableFields() to add in the field value the user
    can select
  • Override getDataObjects() to provide your own logic for selecting
    the data objects to include in the report.

Reply to this email directly or view it on GitHub:
#1 (comment)

@nyeholt
Copy link
Owner

nyeholt commented Sep 22, 2011

The important bit is

Uncaught Exception: Abstract method called; please implement getDataObjects()

Your report subclass needs to implement this method to return the actual data objects that will be displayed in the report. Check the DataObjectReport class for an example.

@srmcatee
Copy link
Author

K. That is fixed.

Now my final issue. I'm trying to include fields from a hasmany table that relates to my primary table.

I modified getReportableFields to reference one of my other tables. In the example code below I have a primary table "Family" and another table "Individual". The relationship that relates them is "Individuals". So here is the code:

protected function getReportableFields() {
$fields = array(
'ID' => 'ID',
'Created' => 'Created',
'LastModified' => 'LastModified',
);
if ($this->ReportOn) {
$dbfields = Object::combined_static($this->ReportOn, 'db');
$addtl=array('Individuals.FirstName'=>'Individuals.FirstName');
$fields=array_merge($fields,$dbfields);
$fields=array_merge($fields,$addtl);
$fields = array_combine(array_keys($fields), array_keys($fields));
....

The field is displayed but comes up blank when I generate the report. How do I get the report to pull the selected field value from a hasmany relationship?

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants