Skip to content

Creating a model/struct for SQL views #1481

Answered by groue
robbevp asked this question in Q&A
Discussion options

You must be logged in to vote

Hello @robbevp,

Let's start from the error message:

SQLite error 1: no such table: score

The reason why you see this message is that Player.including(optional: Player.score) uses Player.score, an association from Player to Score. GRDB thus looks for the table for Score, which, by default, is named like the record type itself: score.

But your schema has no score table. Instead it has a playerScore view. The fact that it is a view is not a problem (as long as we don't try to write into it). But we need to help GRDB making the link between the table and the view. See the "👉" comments below:

struct Player: Identifiable, Equatable, Codable, FetchableRecord, MutablePersistableRecord {
    var id

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@groue
Comment options

@robbevp
Comment options

@groue
Comment options

@groue
Comment options

@robbevp
Comment options

Answer selected by robbevp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants