////
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.
////

=== Creating Domain Classes

When using RxGORM each entity that you persist to the database is known as a domain class.

If you are using RxGORM within Grails you can create a domain class with the `create-domain-class` command provided by the command line. Alternatively if you are not using Grails simply creating a Groovy class within `src/main/groovy` of your project will suffice.

A domain class must as a minimum implement the link:../api/grails/gorm/rx/RxEntity.html[RxEntity] trait.

However, when using RxGORM for MongoDB you should instead implement the `grails.gorm.rx.mongodb.RxMongoEntity` trait. For example:

[source,groovy]
----
package example

import grails.gorm.rx.mongodb.*
import org.bson.types.ObjectId

class Book implements RxMongoEntity<Book> {
    ObjectId id
    String title
}
----

NOTE: The type is provided as a generic argument to the `RxMongoEntity` trait. This is important to ensure the correct return signatures are produced for methods provided by the trait.

In addition, for MongoDB an `id` of type `ObjectId` is required.

For more information on domain modelling in GORM, take a look at the https://docs.grails.org/latest/guide/GORM.html#domainClasses[GORM user guide] on the subject.
