We we define joins between tables, adopted from Data module, we can then create relationships inside Views.
However, then, edit link is not working properly.
Error: Notice: Undefined property: stdClass::$#### in data_entity_views_handler_field_edit_link->render() (line 30 of ####\sites\all\modules\data\data_entity\views\data_entity_views_handler_field_edit_link.inc).
If we print serialized the "$values" inside that function, we get
O:8:"stdClass":18:{s:37:"monitoringstation_monitoringstationid";s:1:"1";s:39:"monitoringstation_monitoringstationname";s:16:"Lake Vouliagmeni";s:39:"monitoringstation_monitoringstationcode";s:6:"HYM005";s:24:"monitoringstation_areaid";s:1:"1";s:9:"area_area";s:8:"12.30000";s:13:"area_areacode";s:3:"HYM";s:33:"monitoringstation_geodeticdatumid";N;s:32:"monitoringstation_gpsequipmentid";N;s:33:"monitoringstation_descriptionsite";s:37:"below rock cliff of Lake Vouliagmeni ";s:29:"monitoringstation_altitudegps";N;s:35:"monitoringstation_altitudealtimeter";N;s:36:"monitoringstation_measurementdategps";N;s:25:"monitoringstation_gpstime";N;s:37:"monitoringstation_measurementerrorgps";N;s:40:"monitoringstation_decimaldegreeslatitude";N;s:41:"monitoringstation_decimaldegreeslongitude";N;s:35:"monitoringstation_establishmentdate";N;s:32:"monitoringstation_completiondate";N;}
(I have two base tables, monitoringstation and area, conecting with areaid)
While, whithout relationship the view for the monitoringstation table, gives for the same variable:
O:8:"stdClass":16:{s:19:"monitoringstationid";s:1:"1";s:39:"monitoringstation_monitoringstationname";s:16:"Lake Vouliagmeni";s:39:"monitoringstation_monitoringstationcode";s:6:"HYM005";s:24:"monitoringstation_areaid";s:1:"1";s:33:"monitoringstation_geodeticdatumid";N;s:32:"monitoringstation_gpsequipmentid";N;s:33:"monitoringstation_descriptionsite";s:37:"below rock cliff of Lake Vouliagmeni ";s:29:"monitoringstation_altitudegps";N;s:35:"monitoringstation_altitudealtimeter";N;s:36:"monitoringstation_measurementdategps";N;s:25:"monitoringstation_gpstime";N;s:37:"monitoringstation_measurementerrorgps";N;s:40:"monitoringstation_decimaldegreeslatitude";N;s:41:"monitoringstation_decimaldegreeslongitude";N;s:35:"monitoringstation_establishmentdate";N;s:32:"monitoringstation_completiondate";N;}
Notice the change for the primary value, monitoringstationid and monitoringstation_monitoringstationid.
Is this helpful?
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | edit_relationships_views-1488904-6.patch | 1.38 KB | sheldon rampton |
Comments
Comment #1
joachim commentedYup, that means that data_entity_views_handler_field_edit_link needs to be cleverer in its getting of the field key -- basically it needs to look in the $this->aliases IIRC.
Comment #2
xaris.tsimpouris commentedHow do you think of this?
Apparently, it is not the best thing - but at least this is what I will do for now.
(I have no idea to upload it as a patch. If you believe that it will be helpful, please create one. Thank you in advance.)
Comment #3
Tim_MA commentedThank you, this fixed a ton of errors I was getting!
Comment #4
diggingrelic commentedThat definitely fixed a ton of errors for me too. When I have some time later I will create a patch and submit.
Comment #5
imclean commented#2 xaris.tsimpouris, see the Patches page, including the links under "Creating Patches "
Comment #6
sheldon rampton commentedHere's a patch based on the code changes that xaris.tsimpouris proposed.
Comment #6.0
sheldon rampton commentedAdded second example
Comment #7
betoaveigaThis error is related with a wrong assignment of $view->base_table inside data_ui_views_default_views.
Try these:
- Create a table with 2 fields. First field for id (pk/serial), and second field to reference a node. Both fields numeric.
- Populate your entity with some data.
- Click on view records and the edit link in the view will work (right now the base_table of the view is [table_name]).
Then...
- In the second field of our recently created table set a join with node.nid (left join). Save.
- Visit the view again and you'll see multiple empty records (depending on how many nodes you have in your site) and multiple errors, because the base_table of the view changed from [table_name] to 'node', and the edit link get's somehow confused with this change.
I find useful to mantain the base_table the same as the name of the table, no matter if the table have fields with joins. To do so you could edit data_ui_views_default_views or overwrite the generated view with hook_views_default_views_alter.
Hope that helps.
Comment #8
theorichel commentedI have applied the patch. The error message about 'undefined property' has disappeared, but the edit link still doesnt open a form en leads only to an overview of the adopted table where I can click the view.
Comment #9
theorichel commentedI have partly solved this and am continuing this here: https://www.drupal.org/node/1572740#comment-11760023
Comment #10
jerry commentedWorking fine here. Let's RTBC it.
Comment #11
joachim commentedI really don't like the use of the error-suppressing operator. Use isset() and an if() rather than counting on silent error and checking for empty!
(Also, patch has whitespace changes and an unrelated docs change and debug code.)
Also:
> Yup, that means that data_entity_views_handler_field_edit_link needs to be cleverer in its getting of the field key -- basically it needs to look in the $this->aliases IIRC.
I still think that's the right way to do this.
Comment #12
roderikApart from the issues with the patch (which should not have been converted into a for-review patch as-is and not been set to RTBC as-is)...
...the question I have/had here is - are we absolutely sure that the field ($table . '_' . $this->view->base_field) always exists in the view?
I don't know enough about Views to answer that, but I did have to solve it when I wanted to make the edit link work with multi-field primary keys, in #2744843: Remove Entity ID field requirement. The patch there creates a base handler class which includes the "aliases" code, and also makes sure that the needed ID fields are added to the query in query().
...but that patch does more: it moves the whole edit link from data_entity to data_ui. So, for now, this is just a FYI that there's code in there which should solve these issues. So that's an FYI.
---
(What it does not solve yet, is the issue reported by BetoAveiga in #7. The fact that the base table is sometimes changed, is part data_ui_views_default_views(). I don't know enough details about Views joins vs. relationships, to be able to see exactly how that code is wrong. But it certainly does break default views in some circumstances, depending on the join you add to a table in the Data/table structure edit screen.)