Android使用DBFlow创建简单的OneToMany关系 [英] Android create simple OneToMany Relation with DBFlow
问题描述
我有两个简单的模型,我试图在它们之间创建一个简单的OneToMany,就我是使用该库的新手而言,我不能使用库文档,我的主要模型是:
i have simple two models and i'm trying to create simple OneToMany between them, as far as i'm newbie to use this library i can't use library documentation, my main model is:
@Table(database = AppDatabase.class)
public class ModelChannelPosts extends BaseModel {
@PrimaryKey
private int id;
@Column
private String channelId;
@Column
private List<ModelVideos> channel_video_containers;
@Column
private String createdAt;
@Column
private String updatedAt;
public ModelChannelPosts() {
}
@OneToMany(methods = {OneToMany.Method.ALL}, variableName = "channel_video_containers")
public List<ModelVideos> getVideos() {
if (channel_video_containers == null || channel_video_containers.isEmpty()) {
channel_video_containers = new Select()
.from(ModelVideos.class)
.where(ModelVideos_Table.channelId.eq(id))
.queryList();
}
return channel_video_containers;
}
...
}
并且有很多ModelVideos
,则ModelVideos
属于ModelChannelPosts
:
@Table(database = AppDatabase.class)
public class ModelVideos extends BaseModel {
@PrimaryKey
private int id;
@Column
private String fileName;
@Column
private String videoLength;
@Column
private int channelId;
public ModelVideos() {
}
...
}
是未知的,并且出现此错误: in 我如何为他们实现 how can i implementing 这可能会晚一些,但对其他开发人员会有所帮助.
一对多关系将是这样 This might be late but it would be helpfull for other developers.
One to Many Relation will be like this 和 这篇关于Android使用DBFlow创建简单的OneToMany关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!ModelChannelPosts_Table
文件model.channel_video_containers
中的ModelChannelPosts_Table
file model.channel_video_containers
is unknown and i get this error:Error:(168, 48) error: <identifier> expected
OneToMany
?(使关系在ModelChannelPosts
上的channel_video_containers
和ModelVideos
上的channelId
之间建立关系?OneToMany
for them?( make relation ship between channel_video_containers
on ModelChannelPosts
and channelId
on ModelVideos
?推荐答案
@Table(database = AppDatabase.class)
public class ModelChannelPosts extends BaseModel {
@PrimaryKey
private int id;
@Column
private String channelId;
private List<ModelVideos> channel_video_containers;
@Column
private String createdAt;
@Column
private String updatedAt;
public ModelChannelPosts() {
}
@OneToMany(methods = {OneToMany.Method.ALL}, variableName = "channel_video_containers")
public List<ModelVideos> getVideos() {
if (channel_video_containers == null || channel_video_containers.isEmpty()) {
channel_video_containers = new Select()
.from(ModelVideos.class)
.where(ModelVideos_Table.modelChannelPosts_id.eq(id))
.queryList();
}
return channel_video_containers;
}
...
}
ModelVideos
类就像@Table(database = AppDatabase.class)
public class ModelVideos extends BaseModel {
@PrimaryKey
private int id;
@Column
private String fileName;
@Column
private String videoLength;
@Column
private int channelId;
@ForeignKey(stubbedRelationship = true)
ModelChannelPosts modelChannelPosts;
public ModelVideos() {
}
...
}