Why One-to-one relationship dosen't work?
        Posted  
        
            by eugenn
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by eugenn
        
        
        
        Published on 2010-06-13T15:54:16Z
        Indexed on 
            2010/06/13
            16:02 UTC
        
        
        Read the original article
        Hit count: 265
        
I'm trying to create a very simple relationship between two objects. Can anybody explain me why I can't find the Company object via findBy method?
class Company {
    String name
    String desc
    City city
    static constraints = {
        city(unique: true)
    }
}
class City {
    String name
    static constraints = {
    }
}
class BootStrap {
    def init = { servletContext ->
        new City(name: 'Tokyo').save()
        new City(name: 'New York').save()
        new Company(name: 'company', city: City.findByName('New York')).save()
        def c = Company.findByName('company') // Why c=null????!
    }
    def destroy = {
    }
} 
        © Stack Overflow or respective owner