# Import scripts fail to relate topics and posts

**URL:** <https://meta.discourse.org/t/import-scripts-fail-to-relate-topics-and-posts/60377>\
**Category:** Development\
**Created:** [3. April 2017 um 12:56 UTC](https://meta.discourse.org/t/import-scripts-fail-to-relate-topics-and-posts/60377 "2017-04-03T12:56:34Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)\
**Post date:** [3. April 2017 um 18:21 UTC](https://meta.discourse.org/t/import-scripts-fail-to-relate-topics-and-posts/60377/2 "2017-04-03T18:21:58Z")

</div>

The `topic_lookup_from_imported_post_id()` method returns a hash.

> <https://github.com/discourse/discourse/blob/main/script/import_scripts/base/lookup_container.rb#L92-L96>

So, I’d rewrite your function to something like this:

```ruby
create_posts(posts, total: total) do |t|
  parent = topic_lookup_from_imported_post_id(t["Thread_ID"])
  next unless parent
  source_user_id = @usernamesMap[t["username"]]
  opts = {
     id: t['id'],
     user_id: user_id_from_imported_user_id(source_user_id) || Discourse::SYSTEM_USER_ID,
     raw: t["Post_Description"],
     created_at: t["created_at"],
     title: t["title"],
     topic_id: parent[:topic_id],
     reply_to_post_number: parent[:post_number]
   }
end

```

---

_[View the full topic](https://meta.discourse.org/t/import-scripts-fail-to-relate-topics-and-posts/60377)._
