Office Hours — Today, December 13

Tuesday, December 11

Dec 13
8:50 AM
Mark M.
has entered the room
Mark M.
turned on guest access
8:55 AM
Ahmad M.
has entered the room
9:00 AM
Ahmad M.
hi Mr.Mark i have question about Room Database
Mark M.
hi! go right ahead!
Ahmad M.
View paste (33 more lines)
i have Todo Entity that has Reminder Object  `
@Entity(tableName = "todo" ,
        foreignKeys = @ForeignKey(
                entity = listOfTodo.class,
                parentColumns = "uniqueListId",
                childColumns = "uniqueTodoId" ,
                onDelete = ForeignKey.CASCADE) ,
        indices = @Index(value = "uniqueTodoId" ,unique = true))

public class TodoModel {

    @NotNull
    @PrimaryKey
    public final String uniqueTodoId;

...
View paste (6 more lines)
the issue is with the Repeat Type `@TypeConverters({TypeConvertersModel.class})
public class Repeat {

    public int repeatingType;

    @Embedded
    public RepeatUntil repeatUntil;

    public Calendar startRepeatOn;

    @Embedded
    public CustomRepeat customRepeat;

    public Repeat(int repeatingType, RepeatUntil repeatUntil, CustomRepeat customRepeat) {
        this.repeatingType = repeatingType;
...
9:05 AM
Ahmad M.
the user may chose one type of repeat types
i want to store one of different types of Repeat types
View paste (10 more lines)
public class RepeatType {

    static {
        final int DOSE_NOT_REPEAT_TYPE = 0x00000004; // zero calender
        final int DAILY_REPEAT_TYPE = 0x00000005; // one calender
    }

    static { // Weekly Repeat Types
        final int ONE_DAY_IN_THE_WEEK_REPEAT_TYPE=0x00000006; // one calender
        final int DAYS_IN_THE_WEEK_REPEAT_TYPE=0x00000006;
    }

    static { // Monthly repeat Types
        final int MONTHLY_REPEAT_TYPE = 0x00000007; // one calender
        final int MONTHS_IN_THE_YEAR_REPEAT_TYPE = 0x00000018;
...
those my repeating types how i build database for this
Mark M.
you seem to have a field for this int value in Repeat
9:10 AM
Mark M.
I do not know where Repeat belongs with respect to the rest of your database -- perhaps it should be an @Embedded field on TodoModel
Ahmad M.
yes , but i think Repeat should belongs for Todos with Reminder
if Todo has Reminder it may has Repeat also
Mark M.
OK, so, perhaps there should be an @Embedded Repeat field on Reminder, then
Ahmad M.
i do not know if the user want his Todo with Repeat in Monthly or Weekly ..
Mark M.
personally, I usually think of the to-do item as being what repeats, not the reminder
Ahmad M.
i want to create for Example a WeeklyModel at runTime
Mark M.
regardless, somewhere, you will need to ask the user what repeat interval the user wants for this particular to-do or reminder
9:15 AM
Mark M.
so, either design the data model that you want, then create a UI that matches the data model, or mock up the UI that you want, then create a data model that reflects that UI
Ahmad M.
i aready creat The UI
Mark M.
OK, so, where are you asking the user for the repeat interval?
Ahmad M.
pleas minute
9:20 AM
Ahmad M.
Mark M.
from this, it would appear that TodoModel should hold the Repeat data
Ahmad M.
this when prees Weekly
Mark M.
this screen, though, illustrates a more complex rule than what your Repeat class can support
a collection of Repeat objects might be able to represent this rule
Ahmad M.
yes that i come for (:
Mark M.
if you think that will work, then there would be some separate table for the Repeat data, and a 1:N relationship between TodoModel and that Repeat entity
you would set that up to be similar to how you have a relationship between TodoList(?) and TodoModel, using a @ForeignKey
Ahmad M.
yes i haf that
View paste (11 more lines)

@Entity( tableName = "lists_of_todo" , indices = @Index(value = "uniqueListId" ,unique = true))
public abstract class listOfTodo {

    @NotNull
    @PrimaryKey
    public final String uniqueListId;

    public final long creationTime;

    public String title;

    public String description;

    public int priority;
...
this the list entity
Mark M.
so, just as listOfTodo has a relation to TodoModel, TodoModel would have a relation to Repeat
9:25 AM
Ahmad M.
but the query going to be hard
Mark M.
your Repeat class would have a todoModelId field that you use for the relation
your DAO would have a @Query that can return the List<Repeat> for a given TodoModel's ID
9:30 AM
Ahmad M.
ok how i suppose to set the relation between Todomodel and Repeat as foreiginKey
??
Mark M.
View paste
foreignKeys = @ForeignKey(
                entity = TodoModel.class,
                parentColumns = "uniqueTodoId",
                childColumns = "uniqueRepeatId" ,
                onDelete = ForeignKey.CASCADE)
(off the cuff -- it has been a couple of months since I wrote a @ForeignKey)
Repeat would need an @Entity annotation, and you would need to add a @PrimaryKey column (here referred to as uniqueRepeatId, to match your existing naming convention)
so, just as you have tables for the lists and for the todos, you would have a table for the repeat rules
9:35 AM
Ahmad M.
all my problems is in how to design Databaes
thank you so much for your help
Mark M.
you're welcome!
10:00 AM
Mark M.
OK, that is a wrap for today's caht
er, chat
the next chat is Saturday at 4pm US Eastern
the transcript for today's chat will be posted on https://commonsware.com/office-hours/ shortly
have a pleasant day!
Ahmad M.
has left the room
Mark M.
turned off guest access

Tuesday, December 11

 

Office Hours

People in this transcript

  • Ahmad Mustafa
  • Mark Murphy