Я создал DatabaseView, чтобы объединить две таблицы.Когда я делаю свой запрос, я не могу выбрать из таблицы представления базы данных.Но это может быть тип возврата.Это дает мне не может разрешить символ EmployeeWithRole.Я использую roomVersion = '2.1.0-alpha04
Мои объекты:
@Entity(tableName = "EmployeeRole")
data class EmployeeRole(
@PrimaryKey
val id: Id,
@ColumnInfo(name = "role")
val role: String,
@ColumnInfo(name = "parentRole")
val parentRole: Id?)
@Entity(tableName = "Employee",
foreignKeys = [
ForeignKey(entity = EmployeeRole::class,
onDelete = ForeignKey.CASCADE,
parentColumns = ["id"],
childColumns = ["currentRoleId"]
)])
data class Employee(
@PrimaryKey
val id: Id,
@ColumnInfo(name = "firstName")
val firstName: String,
@ColumnInfo(name = "lastName")
val lastName: String,
@ColumnInfo(name = "currentRoleId")
var currentRoleId: Id,
@ColumnInfo(name = "pictureUrl")
var pictureUrl: String)
Мой Dao:
@Dao
Interface EmployeeWithRoleDao {
@Query(" SELECT * FROM EmployeeWithRole ")
fun getAllEmployees(): List<EmployeeWithRole>
}
Просмотр моей базы данных:
import androidx.room.DatabaseView
import androidx.room.Embedded
@DatabaseView("""
SELECT Employee.*, $employeeRoleParams FROM Employee
INNER JOIN EmployeeRole ON Employee.currentRoleId = EmployeeRole.id
""")
data class EmployeeWithRole(
@Embedded
val employee: Employee,
@Embedded(prefix = employeeRoleP)
val employeeRole: EmployeeRole
)
private const val employeeRoleP = "EmployeeRole"
private const val employeeRoleParams = """
$employeeRoleP.id as ${employeeRoleP}_id,
$employeeRoleP.role as ${employeeRoleP}_role,
$employeeRoleP.parentRole as ${employeeRoleP}_parentRole
"""