title: How to update the nested tables in sql using gorm?
body: <p>Here the code is written in Go. I am using two tables where one table has a foreign key that refers to the other table's primary key. Let's say I have a database as following struct defined:</p>
  
  <pre><code>   type User struct{
         ID uint `gorm:"primary_key;column:id"`
         Name string `gorm:"column:name"`
         Place place
         PlaceID
     }
  
     type Place struct{
         ID uint `gorm:"primary_key;column:id"`
         Name string `gorm:"column:name"`
         Pincode uint `gorm:"column:pincode"`
     }
  </code></pre>
  
  <p>And the sql schema is:</p>
  
  <pre><code>create table place(
      id int(20) NOT NULL AUTO_INCREMENT,
      name varchar(100) NOT NULL,
      pincode uint(20) NOT NULL,
      PRIMARY KEY (id),
  )
  
  create table user(
      id int(20) NOT NULL AUTO_INCREMENT,
      name varchar(100) NOT NULL,
      place_id uint(20) NOT NULL,
      PRIMARY KEY (id),
      FOREIGN KEY (place_id) REFERENCES place(id)
  )
  </code></pre>
  
  <p>Now while inserting in user by gorm as:</p>
  
  <pre><code>  place := Place{Name:"new delhi",Pincode:1234}
    user := User{Name: "sam", Age: 15, Place: place}
    err = db.Debug().Create(&amp;user).Error
  
    //It  inserts to both user and place table in mysql
    //now while updating to name in user table as Samuel and place as 
    //following
  
    place := Place{Name:"mumbai",Pincode:1234}
    err = db.Debug().Model(&amp;User{}).Where("id =?", 
     1,).Update(&amp;user{Name:"Samuel",Place:place}).Error
  </code></pre>
  
  <p>It updates the row in user table but creates a new row in place table.But it should update the matching row in place table  and not create a new one</p>
  
  <p>Is there any way to do it? Here I am not using auto migrate function to create db tables.</p>