Search code examples
androidactiveandroidlibs

ActiveAndroid Nested Model


I am using ActiveAndroid and have two models:

@Table(name = "Topics")
public class Topic extends Model {
@Column(name = "Name") String name;

@SerializedName("id")
@Column(index = true,
        unique = true,
        onUniqueConflict = Column.ConflictAction.REPLACE) public long topic_id;
@Column(name = "Counts",
        onUpdate = Column.ForeignKeyAction.CASCADE,
        onDelete = Column.ForeignKeyAction.CASCADE) Counts counts;
}

and

@Table(name = "Counts")
public class Counts extends Model {
@Column(name = "Users") int users;
}

Constructors have been excluded for brevity. Now, when i save Topic, I expect the Counts to be saved. But it does not. I am using gson to create the models from json. Any reason why counts are not being loaded?


Solution

  • First you have to call count.save() then you can call topic.save(). ActiveAndroid needs the id to get the reference and that happen when you save it.