Skip to content
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

Wrong reference generation / PRAGMA foreign_keys not set #32

Merged
merged 2 commits into from
Apr 11, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/com/activeandroid/DatabaseHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ public DatabaseHelper(Context context) {
// OVERRIDEN METHODS
//////////////////////////////////////////////////////////////////////////////////////

@Override
public void onOpen(SQLiteDatabase db) {
if (SQLiteUtils.FOREIGN_KEYS_SUPPORTED) {
db.execSQL("PRAGMA foreign_keys=ON;");
Log.i("Foreign Keys supported. Enabling foreign key features.");
}
};

@Override
public void onCreate(SQLiteDatabase db) {
if (SQLiteUtils.FOREIGN_KEYS_SUPPORTED) {
Expand Down Expand Up @@ -202,4 +210,4 @@ private static int getDbVersion(Context context) {

return aaVersion;
}
}
}
3 changes: 2 additions & 1 deletion src/com/activeandroid/util/SQLiteUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public static String createTableDefinition(TableInfo tableInfo) {
TextUtils.join(", ", definitions));
}

@SuppressWarnings("unchecked")
public static String createColumnDefinition(TableInfo tableInfo, Field field) {
String definition = null;

Expand Down Expand Up @@ -162,7 +163,7 @@ else if (ReflectionUtils.isSubclassOf(type, Enum.class)) {
}

if (FOREIGN_KEYS_SUPPORTED && ReflectionUtils.isModel(type)) {
definition += " REFERENCES " + tableInfo.getTableName() + "(Id)";
definition += " REFERENCES " + Cache.getTableInfo((Class<? extends Model>) type).getTableName() + "(Id)";
definition += " ON DELETE " + column.onDelete().toString().replace("_", " ");
definition += " ON UPDATE " + column.onUpdate().toString().replace("_", " ");
}
Expand Down