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

More tests for eager loading of hasMany associations #563

Merged
merged 3 commits into from
Jun 30, 2019

Conversation

groue
Copy link
Owner

@groue groue commented Jun 29, 2019

This PR adds nothing but new tests for eager loading of hasMany associations. It happened that a few days ago I wrote a request and was just not quite sure it would work. It was working (GRDB associations are really neat), but it wasn't explicitly tested yet!

The newly tested requests have the following shape:

struct Source {
    static let middle = /* hasOne or belongsTo or hasOneThrough to Middle */
}
struct Middle {
    static let destinations = /* hasMany or hasManyThrough to Destination */
}

// Fetch Source and its destinations through an eventual middle record,
// with an `including(all:)` wrapped in a `joining(optional:)`:
struct SourceInfo: Decodable, FetchableRecord {
    var source: Source
    var destinations: [Destination]
}
let infos: [SourceInfo] = try Source
    .joining(optional: Source.middle.including(all: Pivot.destinations))
    .asRequest(of: SourceInfo.self)
    .fetchAll(db)

@groue groue merged commit 7defc8e into development Jun 30, 2019
@groue groue deleted the dev/eager-loading-from-optional-to-one branch June 30, 2019 10:50
@groue groue added this to the GRDB 4.2.0 milestone Jul 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant