Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Importing To Model Admin with a has_one relationship


Reply


1157 Views

Avatar
Bambii7

Community Member, 254 Posts

22 September 2009 at 3:30pm

Edited: 22/09/2009 3:46pm

Hey all,
I've been searching and experimenting for a little while now without success.
I'm trying to import data from a CSV file, to my managed model.
I recently found out you can use the object->add() function to add a object to a many_many relationship (thanks to willr I think).
I'm trying to add a relationship to a newly created object with an existing one when importing. So similar functionality to the $object->add($anotherObject). But I'm unsure of the syntax (or if it's possible) in the csv file.

I've been trying things in my CSV like "Relationship.add" as a column title, then the ID of the existing object in the column...... If anyone knows how to do this, the solution would be fab. I'm going to see if I can find an example by exporting, but only the summary_fields export which makes it tricky.

EDIT: I'm adding my relationship.ID (for me it's Venue.ID) as a summary field and as a searchable field, which seems to allow it to export the id of the related object. But when reimporting the spreed sheet, SS creates new empty objects instead of associating the ID.