Skip to content

Commit b9c3b19

Browse files
committed
Merge branch 'woomob-1210-relationship-based-mapping-and-saving-for-POS-entities' into woomob-1210-tests-for-saving-pos-models
2 parents e9fc1ce + 435502f commit b9c3b19

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

Modules/Sources/Yosemite/Model/Storage/PersistedProduct+Conversions.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ extension PersistedProduct {
4444
}
4545

4646
func toPOSProduct(db: GRDBDatabaseConnection) throws -> POSProduct {
47-
let images = try db.read { db in
48-
return try request(for: PersistedProduct.images).fetchAll(db)
49-
}
50-
let attributes = try db.read { db in
51-
return try request(for: PersistedProduct.attributes).fetchAll(db)
47+
let (images, attributes) = try db.read { db in
48+
let images = try request(for: PersistedProduct.images).fetchAll(db)
49+
let attributes = try request(for: PersistedProduct.attributes).fetchAll(db)
50+
return (images, attributes)
5251
}
52+
5353
return toPOSProduct(
5454
images: images.map { $0.toProductImage() },
5555
attributes: attributes.map { $0.toProductAttribute(siteID: siteID) }
@@ -96,7 +96,7 @@ extension PersistedProductAttribute {
9696
func toProductAttribute(siteID: Int64) -> ProductAttribute {
9797
return ProductAttribute(
9898
siteID: siteID,
99-
attributeID: 0,
99+
attributeID: id ?? 0,
100100
name: name,
101101
position: Int(position),
102102
visible: visible,

Modules/Sources/Yosemite/Model/Storage/PersistedProductVariation+Conversions.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ extension PersistedProductVariation {
3838
}
3939

4040
func toPOSProductVariation(db: GRDBDatabaseConnection) throws -> POSProductVariation {
41-
let image = try db.read { db in
42-
return try request(for: PersistedProductVariation.image).fetchOne(db)
43-
}
44-
let attributes = try db.read { db in
45-
return try request(for: PersistedProductVariation.attributes).fetchAll(db)
41+
let (image, attributes) = try db.read { db in
42+
let image = try request(for: PersistedProductVariation.image).fetchOne(db)
43+
let attributes = try request(for: PersistedProductVariation.attributes).fetchAll(db)
44+
return (image, attributes)
4645
}
46+
4747
return toPOSProductVariation(
4848
attributes: attributes.map { $0.toProductVariationAttribute() },
4949
image: image?.toProductImage()

0 commit comments

Comments
 (0)