0

I'm trying to access TABLE_NAME from ProductTable in ProductImageTable to put it in the query. I've searched everywhere on how to access it and so far I've found nothing. I would appreciate some help, please :)

Here's a snippet of the code :

abstract inner class ProductTable : Table() {
    val TABLE_NAME: String = "product"
}

abstract inner class ProductImageTable : Table() {
    val SQL_CREATE_TABLE : String = "CREATE TABLE $TABLE_NAME" +
            " ($_ID$ID_TYPE_AUTO_INC$COMMA_SEP" +
            "$COLUMN_PRODUCT_UUID$TEXT_TYPE_NOT_NULL$COMMA_SEP" +
            "$COLMUN_LOCAL_IMAGE_FILE$TEXT_TYPE_NOT_NULL_EMPTY$COMMA_SEP" +
            "$COLUMN_SERVER_IMAGE_URL$TEXT_TYPE_NOT_NULL_EMPTY$COMMA_SEP" +
            "FOREIGN KEY($COLUMN_PRODUCT_UUID) REFERENCES ${ProductTable.TABLE_NAME}(${ProductTable.COLUMN_PRODUCT_UUID}) ON UPDATE CASCADE ON DELETE CASCADE)"
}
Mario SG
  • 151
  • 7
Jing Wey
  • 58
  • 3

1 Answers1

0

Try

abstract inner class ProductImageTable : ProductTable() {

if you inherit from that class where that field is then you should be able to access it.

Also you could make your TABLE_NAME val a const (see https://stackoverflow.com/a/37596023/2399024 for mor infos about const):

const val TABLE_NAME: String = "product"

BTW: Maybe you might want to use https://developer.android.com/jetpack/androidx/releases/room instead of manually doing sql query stuff

donfuxx
  • 10,696
  • 6
  • 41
  • 74
  • Thanks for the answer! :) I put everything in an companion object, so I can now access the variables. – Jing Wey Nov 04 '19 at 09:46