-
Notifications
You must be signed in to change notification settings - Fork 133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use direct associations with Orma v2 #312
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,17 @@ | ||
package io.github.droidkaigi.confsched.model; | ||
|
||
import android.content.Context; | ||
import android.support.annotation.Nullable; | ||
import android.text.TextUtils; | ||
import com.google.gson.annotations.SerializedName; | ||
|
||
import com.github.gfx.android.orma.annotation.Column; | ||
import com.github.gfx.android.orma.annotation.PrimaryKey; | ||
import com.github.gfx.android.orma.annotation.Table; | ||
import com.google.gson.annotations.SerializedName; | ||
|
||
import org.parceler.Parcel; | ||
|
||
import android.content.Context; | ||
import android.support.annotation.Nullable; | ||
import android.text.TextUtils; | ||
|
||
import java.util.Date; | ||
|
||
import io.github.droidkaigi.confsched.R; | ||
|
@@ -19,6 +21,7 @@ | |
@Table | ||
public class Session { | ||
|
||
@PrimaryKey(auto = false) | ||
@Column(indexed = true) | ||
@SerializedName("id") | ||
public int id; | ||
|
@@ -31,9 +34,7 @@ public class Session { | |
@SerializedName("description") | ||
public String description; | ||
|
||
@Column | ||
public int speakerId; | ||
|
||
@Column(value = "speakerId", indexed = true) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Awesome...! This is just what I wanted to do! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just suggestion of Orma. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might not what you think 💃 Column#value is the column name of the table. As of konifer/droidkaigi2016 v1.0.0, there is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In other words, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! Maybe I understood. |
||
@SerializedName("speaker") | ||
public Speaker speaker; | ||
|
||
|
@@ -45,16 +46,12 @@ public class Session { | |
@SerializedName("etime") | ||
public Date etime; | ||
|
||
@Column(indexed = true) | ||
public int categoryId; | ||
|
||
@Column(value = "categoryId", indexed = true) | ||
@Nullable | ||
@SerializedName("category") | ||
public Category category; | ||
|
||
@Column(indexed = true) | ||
public int placeId; | ||
|
||
@Column(value = "placeId", indexed = true) | ||
@SerializedName("place") | ||
public Place place; | ||
|
||
|
@@ -91,20 +88,6 @@ public Date getDisplayETime(Context context) { | |
return LocaleUtil.getDisplayDate(etime, context); | ||
} | ||
|
||
public void prepareSave() { | ||
speakerId = speaker.id; | ||
if (category != null) categoryId = category.id; | ||
placeId = place.id; | ||
} | ||
|
||
public Session initAssociations(OrmaDatabase orma) { | ||
if (category == null) category = orma.selectFromCategory().idEq(categoryId).value(); | ||
if (place == null) place = orma.selectFromPlace().idEq(placeId).value(); | ||
if (speaker == null) speaker = orma.selectFromSpeaker().idEq(speakerId).value(); | ||
|
||
return this; | ||
} | ||
|
||
public int getLanguageResId() { | ||
switch (languageId) { | ||
case LocaleUtil.LANG_EN_ID: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One question of Orma.
What is this option?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In default settings, Orma's
@PrimaryKey
is automatically assigned by SQLite, even ifautoincrement = true
is not specified.In this case, each ID comes from the API so it is not an "auto" value.
You can see the difference in
Contributor_Schema.java
by comparing both cases:@PrimaryKey(auto = true)
(default) and@PrimaryKey(auto = false)
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realized it. Thanks!