torbjorn-boost opened a new issue, #14434:
URL: https://github.com/apache/grails-core/issues/14434

   Hello. I hope this is the right place for this issue, and that it has enough 
information:
   
   So I have these two classes:
   ```
   class Lol {
   
       Long id
       String name
   
       List<Omg> omgs = new ArrayList<>()
   
       static hasMany = [
           omgs: Omg
       ]
   
       static mappedBy = [
           omgs: 'lol'
       ]
   
       static mapping = {
           id generator: 'sequence', params:[sequence:'lol_seq']
           omgs indexColumn: [
               name: 'lol_index'
           ]
       }
   }
   ```
   
   ```
   package ai.boost
   
   class Omg {
   
       Long id
       String name
   
       Lol lol
   
       static constraints = {
           lol nullable: true
       }
   
       static mapping = {
           id generator: 'sequence', params: [sequence: 'omg_seq']
       }
   }
   ```
   
   And the SQL:
   ```
   CREATE SEQUENCE lol_seq;
   CREATE TABLE lol (
     id BIGINT PRIMARY KEY DEFAULT NEXTVAL('lol_seq'),
     name text
   );
   
   CREATE SEQUENCE omg_seq;
   CREATE TABLE omg (
     id BIGINT PRIMARY KEY DEFAULT NEXTVAL('omg_seq'),
     name text,
     lol_id BIGINT REFERENCES lol(id),
     lol_index INT
   );
   ```
   
   Basically, a Lol has an ordered list of omgs.
   
   The following code works fine:
   ```
   Lol lol = new Lol(name: 'Lol 1');
   Omg omg1 = new Omg(name: 'Omg 1')
   Omg omg2 = new Omg(name: 'Omg 2')
   Omg omg3 = new Omg(name: 'Omg 3')
   lol.addToOmgs(omg1)
   lol.addToOmgs(omg2)
   lol.addToOmgs(omg3)
   lol.save(flush: true)
   ```
   I mean, look at this, it's just what I want:
   
![image](https://user-images.githubusercontent.com/30621356/92895731-0f3ae100-f41c-11ea-883f-3e5f203fffa4.png)
   Beatiful!
   
   But, what happens if I want to remove one of the omgs from the list _without 
deleting it_?
   ```
   Lol lol = new Lol(name: 'Lol 1');
   Omg omg1 = new Omg(name: 'Omg 1')
   Omg omg2 = new Omg(name: 'Omg 2')
   Omg omg3 = new Omg(name: 'Omg 3')
   lol.addToOmgs(omg1)
   lol.addToOmgs(omg2)
   lol.addToOmgs(omg3)
   
   lol.save(flush: true)
   
   lol.removeFromOmgs(omg2) // Just added this line
   ```
   This:
   
![image](https://user-images.githubusercontent.com/30621356/92895225-976cb680-f41b-11ea-9ce8-497321d4837d.png)
   What is this? `lol_id` is still `1`, but, in my opinion, should be `NULL`, 
and the same with `lol_index`.
   
   Things I tried that had no effect:
   - `omg2.setLol(null)`
   - Adding `nullable: true` to the `indexColumn`
   - Upgrading from gorm 6.1.9 to 6.1.12
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to