ForeignKey | Define column name of referenced class
See original GitHub issueSetup:
- DBFlow Version:
4.0.0-beta1
- Target Platform:
Android 23
- Gradle/Maven:
Gradle v2.10
Android Gradle Plugin v2.0.0
- Build Tools:
24.0.3
- Kotlin:
1.0.3
withkapt
Issue Kind: Question
Description:
I want to reference a Model from another Model (See below). The problem with the version below is, I get
Cannot find symbol method getFrom()
Cannot find symbol method getTo()
Cannot find symbol method getFrom()
Cannot find symbol method getTo()
@Table(database = MMHDatabase::class)
class Transaction(from: Account? = null, value: Float = 0.0f, to: Account? = null, id: Long = -1) : BaseModel() {
companion object {
fun get(id: Long) : Transaction? {
return (select
from Transaction::class
where (Transaction_Table.id eq id)).result
}
}
@PrimaryKey(autoincrement = true)
var id: Long = -1
@ForeignKey
var from: Account? = null
@Column
var value: Float = 0.0f
@ForeignKey
var to: Account? = null
}
Corresponding generated code (Line 3 and 9):
1public final void bindToInsertValues(ContentValues values, Transaction model) {
2 if (model.getFrom() != null) {
3 values.put("from_id", model.getFrom().getFrom());
4 } else {
5 values.putNull("from_id");
6 }
7 values.put("value", model.getValue());
8 if (model.getTo() != null) {
9 values.put("to_id", model.getTo().getTo());
10 } else {
11 values.putNull("to_id");
12 }
13 }
and (Line 3 and 9)
1 public final void bindToInsertStatement(DatabaseStatement statement, Transaction model, int start) {
2 if (model.getFrom() != null) {
3 statement.bindLong(1 + start, model.getFrom().getFrom());
4 } else {
5 statement.bindNull(1 + start);
6 }
7 statement.bindDouble(2 + start, model.getValue());
8 if (model.getTo() != null) {
9 statement.bindLong(3 + start, model.getTo().getTo());
10 } else {
11 statement.bindNull(3 + start);
12 }
13 }
I expected it would use the get method of the primary key of the Account
class which would be getId()
.
Issue Analytics
- State:
- Created 7 years ago
- Comments:27 (2 by maintainers)
Top Results From Across the Web
Foreign Key Constraint | CockroachDB Docs
The `FOREIGN KEY` constraint specifies a column can contain only values exactly matching existing values from the column it references.
Read more >Mapping a foreign key with a custom column name
The Name value should be a comma separated list of foreign key property names. My entities are like this: [Table("WIDGETENTITIES")] public class WidgetEntity ......
Read more >How to Create a Table with a Foreign Key in SQL
Discussion: Another way to define a foreign key during table creation is to use the FOREIGN KEY REFERENCES clause at the end of...
Read more >13.1.20.5 FOREIGN KEY Constraints - MySQL :: Developer Zone
A foreign key relationship involves a parent table that holds the initial column values, and a child table with column values that reference...
Read more >SQL FOREIGN KEY Constraint - W3Schools
The table with the foreign key is called the child table, and the table with the primary key is called the referenced or...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Assuming
Banca
andIndicatore
are also derived fromBaseModel
and thier ID field isid
and is of typeLong
. Also there must be getter and setter calledsetId
andgetId
.found issue! fixed in
develop
. Sorry for no response (I was on vacation for a little while).