Jump to:

23490 Posts in 18996 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Importing To Model Admin with a has_one relationship

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

Page: 1
Go to End
Author Topic: 1073 Views
  • Bambii7
    Community Member
    254 Posts

    Importing To Model Admin with a has_one relationship Link to this post

    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.

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.