////
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
////


== hasOne



=== Purpose


Defines a bidirectional one-to-one association between two classes where the foreign key is in the child.


=== Examples


[source,groovy]
----
class Face {
    ..
    static hasOne = [nose: Nose]
}
----

[source,groovy]
----
class Nose {
    Face face
}
----

In this example we define a one-to-one relationship between the `Face` class and the `Nose` class


=== Description


Use a `hasOne` association to store the foreign key reference in child table instead of the parent in a bidirectional one-to-one. The example presented above will generate the following table structure:

[source,groovy]
----
create table face (id bigint generated by default as identity (start with 1),
                   version bigint not null,
                   primary key (id))
create table nose (id bigint generated by default as identity (start with 1),
                   version bigint not null,
                   face_id bigint not null,
                   primary key (id))
----

Notice that the foreign key `face_id` is stored in the `nose` table instead of the `face` table as with a normal one-to-one definition without `belongsTo`.
