Skip to content

@BindSqlRelation

xcesco edited this page May 5, 2018 · 2 revisions

For default, every field defined in a class that belongs to the data model of a data source is included as the column in the associated database table. If you don't want to include a particular field into the table, just decorate the field with @BindDisabled or set to false @BindSqlColumn#enabled.

When we work with relationship, it happens that you referer from the parent entity the children entities with a collection field. An example:

@BindTable
public class Album {
  public long id;
  
  @BindSqlColumn(enabled=false)
  public List<Song> songs;
}

@BindTable
public class Song {
  public long id;

  @BindSqlColumn(parentEntity=Album .class, nullable=false)
  public long albumId;
}

There is another way to avoid the inclusion of songs field in table album: using @BindRelation. With this annotation, we inform the Kripton Annotation Processor that the field is not to be inserted in table AND that it can be used to generate child queries.

@BindTable
public class Album {
  public long id;
  
  @BindSqlRelation
  public List<Song> songs;
}

@BindTable
public class Song {
  public long id;

  @BindSqlColumn(parentEntity=Album .class, nullable=false)
  public long albumId;
}

This annotation can be used on List or Set type field. If you remove BindSqlRelation it will be inserted as BLOB.

Table of Contents

Query definition

Features

Relations

Multithread supports

Modularization

Annotations for data convertion

Annotations for SQLite ORM

Annotations for shared preferences

Clone this wiki locally