Embedded class
If you want to use an object that you have defined yourself, in your entity,
you can use this annotation. Suppose that the Note
entity has an
address
property that is an object itself. In this situation, you can
use this annotation on that field. Embedded objects also can have embedded
fields. Embedded object fields, can have Column and Ignore annotation,
but they can't have PrimaryKey.
You should note that the fields of embedded object, merge with
entity fields in table. For example, for the below entity, created table
has these columns: id
, text
, address_lat
and address_lng
.
If you have noticed, embedded object fields has a prefix in its column
name that is field name by default.
You can change this prefix by change prefix property of Embedded
annotation.
@Entity()
class Note {
@PrimaryKey(autoGenerate: true)
final int? id;
final String text;
@Embedded()
final Address? address;
Note({
this.id,
required this.text,
required this.isEdited,
this.address,
});
}
class Address {
@Column(name: 'lat')
final double latitude;
@Column(name: 'lng')
final double latitude;
Address({
required this.latitude,
required this.latitude,
});
}
Properties
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- fields ↔ _EmbeddedFields
-
getter/setter pair