I new to Room, and @Relation isn't clear for me. If I understand correctly, I have entities e.g. (RSS)ChannelEntity, and channel has items named ItemEntity. These are classes wiht @Entity annotation. I also have a POJO to "connect" my entites. I mean I've to write a POJO like this:
public class Channel {
@Embedded
private ChannelEntity channel;
// Link is the primary key in ChannelyEntity
@Relation (parentColumn = "link", entityColumn = "channel_link")
private ArrayList<ItemEntity> items;
// Getters and Setters are here
}
Than I've to write a dao interface where I can get Channel (not ChannelEntity) like this:
public interface ChannelDao {
@Query("SELECT * FROM channels WHERE link = :link LIMIT 1")
Channel getChannelById(String link);
@Query("SELECT * FROM channels")
ArrayList<Channel> getAllChannels();
}
With these Entities, DAOs and POJOs I can get Channel objects which contain a list of Items with the corresponding link (id). Is that right?
My other is question about the rest CRUD. E.g. if I'd like to save a new channel can I add this statement to my ChannelDao?
@Insert(onConflict = OnConflictStrategy.REPLACE)
void createChannels(Channel... channels);
to delete
@Delete
void deleteChannels(Channel... channels);
and so on. So will it create and delete the ChannelEntities and ItemEntities from the passed Channel object?