From 22a328144e296561c7cdcee741168b6eb5cec1ce Mon Sep 17 00:00:00 2001 From: Andrew Grosner Date: Fri, 3 Jul 2015 10:05:56 -0400 Subject: [PATCH] @ContainerKey now respected on foreign column fields such that it references the whole object by that key --- .../dbflow/processor/definition/ColumnDefinition.java | 6 +++--- .../java/com/raizlabs/android/dbflow/test/AQL.java | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/DBFlow-Compiler/src/main/java/com/raizlabs/android/dbflow/processor/definition/ColumnDefinition.java b/DBFlow-Compiler/src/main/java/com/raizlabs/android/dbflow/processor/definition/ColumnDefinition.java index 963516277..97bcbfac3 100644 --- a/DBFlow-Compiler/src/main/java/com/raizlabs/android/dbflow/processor/definition/ColumnDefinition.java +++ b/DBFlow-Compiler/src/main/java/com/raizlabs/android/dbflow/processor/definition/ColumnDefinition.java @@ -307,7 +307,7 @@ public void writeSaveDefinition(JavaWriter javaWriter, boolean isModelContainerA javaWriter.emitStatement("ModelContainer %1s = %1s.getInstance(%1s.getValue(\"%1s\"), %1s.class)", modelDefinition, ModelUtils.getVariable(true), ModelUtils.getVariable(true), - columnFieldName, + containerKeyName, foreignKeyTableClassName); } else { javaWriter.beginControlFlow("if (%1s != null)", modelDefinition); @@ -458,11 +458,11 @@ public void writeLoadFromCursorDefinition(BaseTableDefinition tableDefinition, J if (isModelContainerAdapter && isModel) { javaWriter.emitStatement("%1s.put(\"%1s\",%1s.getData())", ModelUtils.getVariable(true), - columnFieldName, modelContainerName); + containerKeyName, modelContainerName); javaWriter.nextControlFlow("else"); javaWriter.emitStatement("%1s.put(\"%1s\", null)", ModelUtils.getVariable(true), - columnFieldName); + containerKeyName); } javaWriter.endControlFlow(); diff --git a/DBFlow/src/androidTest/java/com/raizlabs/android/dbflow/test/AQL.java b/DBFlow/src/androidTest/java/com/raizlabs/android/dbflow/test/AQL.java index f2d9dfe60..540aa1c22 100644 --- a/DBFlow/src/androidTest/java/com/raizlabs/android/dbflow/test/AQL.java +++ b/DBFlow/src/androidTest/java/com/raizlabs/android/dbflow/test/AQL.java @@ -1,6 +1,7 @@ package com.raizlabs.android.dbflow.test; import com.raizlabs.android.dbflow.annotation.Column; +import com.raizlabs.android.dbflow.annotation.ContainerKey; import com.raizlabs.android.dbflow.annotation.ForeignKey; import com.raizlabs.android.dbflow.annotation.ForeignKeyReference; import com.raizlabs.android.dbflow.annotation.ModelContainer; @@ -37,6 +38,7 @@ public interface Columns { @Column(name = Columns.AQL_TIMESTAMP) private Date timestamp; + @ContainerKey("boxedLodo") @Column @ForeignKey(references = {@ForeignKeyReference(columnName = "id1", columnType = long.class, foreignColumnName = "id"), @ForeignKeyReference(columnName = "id2", columnType = String.class, foreignColumnName = "name")})