title: How can I model this json in the right way with Realm?
body: <p>This is my first time with <a href="https://realm.io/" rel="nofollow noreferrer">Realm</a> and I'm trying to model this JSON, I'm working with <a href="https://github.com/Hearst-DD/ObjectMapper" rel="nofollow noreferrer">ObjectMapper</a> too
        </p>
  
  <pre><code>  {
      companies: [
          {
               id: "1",
               name: "Quisque ut",
               logo: "0",
               company_categories: [
                  "1",
                  "2"
               ]
          }
      ],
      categories: [
          {
               id: "1",
               name: "Category1"
          },
          {
               id: "2",
               name: "Category2"
          },
          {
               id: "3",
               name: "Category3" 
          }
      ]
   }
  </code></pre>
  
  <p>In my app this is the code i'm implementing
      </p>
  
  <pre><code>class Category: Object, Mappable {
      dynamic var id = ""
      dynamic var name = ""
  
      required convenience init?(map: Map) {
          self.init()
      }
  
      func mapping(map: Map) {
          id &lt;- map["id"]
          name &lt;- map["name"]
      }
  
      override static func primaryKey() -&gt; String? {
          return "id"
      }
  }
  </code></pre>
  
  <p>and my object company is like this:
      </p>
  
  <pre><code>class Company: Object, Mappable {
      dynamic var id = ""
      dynamic var name = ""
      dynamic var logo = ""
      let categories = List&lt;Category&gt;()
  
      required convenience init?(map: Map) {
          self.init()
      }
  
      func mapping(map: Map) {
          id &lt;- map["id"]
          name &lt;- map["name"]
          logo &lt;- map["logo"]
  
          var categories: [String]? = nil
          categories &lt;- map["company_categories"]
          let realm = try! Realm()
  
          categories?.forEach { category in
              let categoryObject = realm.objects(Company.self).filter({ $0.id == category }).first
              self.categories.append(categoryObject!)
          }
      }
  
      override static func primaryKey() -&gt; String? {
          return "id"
      }
  }
  </code></pre>
  
  <p>and I got an error like this:</p>
  
  <blockquote>
    <p>Terminating app due to uncaught exception 'RLMException', reason: 'Can not add objects from a different Realm'</p>
  </blockquote>