Permalink
Browse files

Fix for 1-0:1 with shared pk attach bug + Addl tests

  • Loading branch information...
1 parent 802d2a5 commit 8d9a966f77307f592cdebeea1ef68f153d978c38 @jtraband jtraband committed May 6, 2013
@@ -109,7 +109,16 @@ function defaultPropertyInterceptor(property, newValue, rawAccessorFn) {
// TODO: null -> NullEntity later
oldValue.setProperty(inverseProp.name, null);
}
- newValue.setProperty(inverseProp.name, this);
+ if (property.isScalar) {
+ if (inverseProp.relatedDataProperties & !inverseProp.relatedDataProperties[0].isPartOfKey) {
+ // don't update the key if updating a 1-1 inverse relation
+ // TODO: rethink this later as we see more 1-1 relations
+ // what we really want is to only update the inverseProp if it is dependent but we don't have Prin-Dep relns yet.
+ newValue.setProperty(inverseProp.name, this);
+ }
+ } else {
+ newValue.setProperty(inverseProp.name, this);
+ }
} else {
// navigation property change - undo old relation
if (oldValue) {
@@ -33,6 +33,19 @@ define(["testFns"], function (testFns) {
return testFns;
}
+ test("with parameter and count", function() {
+ var em = newEm();
+ var q = EntityQuery.from("CustomerCountsByCountry")
+ .withParameters({ companyName: "C" });
+
+ stop();
+ var r;
+ em.executeQuery(q).then(function(data) {
+ r = data.results;
+ ok(r.length > 0, "should be some results");
+ }).fail(testFns.handleFail).fin(start);
+ });
+
test("with parameter", function () {
var em = newEm();
var q = EntityQuery.from("CustomersStartingWith")
@@ -22,6 +22,19 @@ define(["testFns"], function (testFns) {
}
});
+ //// for now returns an OData message "$count is not supported"
+ //test("$count operator", function () {
+ // stop();
+ // var em = newEm(testFns.newMs());
+ // ok(em, "no em found");
+
+ // var query = "Customers?$filter=startswith(CompanyName, 'A') eq true&$count";
+ // em.executeQuery(query).then(function (data) {
+ // ok(!em.metadataStore.isEmpty(), "metadata should not be empty");
+ // ok(data, "no data");
+
+ // }).fail(testFns.handleFail).fin(start);
+ //});
test("filter and order by", function () {
stop();
@@ -27,6 +27,46 @@ define(["testFns"], function (testFns) {
}
});
+ var wellKnownData = {
+ // ID of the Northwind "Alfreds Futterkiste" customer
+ alfredsID: '785efa04-cbf2-4dd7-a7de-083ee17b6ad2',
+ // ID of the Northwind "Nancy Davolio" employee
+ nancyID: 1,
+ // Key values of a Northwind "Alfreds Futterkiste"'s OrderDetail
+ alfredsOrderDetailKey: { OrderID: 10643, ProductID: 28 /*Rössle Sauerkraut*/ },
+ // ID of Chai product
+ chaiProductID: 1
+ };
+
+ test("can save a Northwind Order & InternationalOrder", 2, function () {
+ // Create and initialize entity to save
+ var em = newEm();
+
+ var order = em.createEntity('Order', {
+ customerID: wellKnownData.alfredsID,
+ employeeID: wellKnownData.nancyID,
+ shipName: "Test " + new Date().toISOString()
+ });
+
+ var internationalOrder = em.createEntity('InternationalOrder', {
+ // I thought Jay fixed this?
+ order: order, // sets OrderID and pulls it into the order's manager
+ // orderID: order.getProperty("orderID"),
+ customsDescription: "rare, exotic birds"
+ });
+ stop();
+ em.saveChanges().then(function(data) {
+
+ var orderId = order.getProperty("orderID");
+ var internationalOrderID = internationalOrder.getProperty("orderID");
+
+ equal(internationalOrderID, orderId,
+ "the new internationalOrder should have the same OrderID as its new parent Order, " + orderId);
+ ok(orderId > 0, "the OrderID is positive, indicating it is a permanent order");
+
+ }).fail(testFns.handleFail).fin(start);
+
+ });
test("raw query string", function () {
var em = newEm();
@@ -4117,7 +4117,16 @@ function defaultPropertyInterceptor(property, newValue, rawAccessorFn) {
// TODO: null -> NullEntity later
oldValue.setProperty(inverseProp.name, null);
}
- newValue.setProperty(inverseProp.name, this);
+ if (property.isScalar) {
+ if (inverseProp.relatedDataProperties & !inverseProp.relatedDataProperties[0].isPartOfKey) {
+ // don't update the key if updating a 1-1 inverse relation
+ // TODO: rethink this later as we see more 1-1 relations
+ // what we really want is to only update the inverseProp if it is dependent but we don't have Prin-Dep relns yet.
+ newValue.setProperty(inverseProp.name, this);
+ }
+ } else {
+ newValue.setProperty(inverseProp.name, this);
+ }
} else {
// navigation property change - undo old relation
if (oldValue) {

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -4117,7 +4117,16 @@ function defaultPropertyInterceptor(property, newValue, rawAccessorFn) {
// TODO: null -> NullEntity later
oldValue.setProperty(inverseProp.name, null);
}
- newValue.setProperty(inverseProp.name, this);
+ if (property.isScalar) {
+ if (inverseProp.relatedDataProperties & !inverseProp.relatedDataProperties[0].isPartOfKey) {
+ // don't update the key if updating a 1-1 inverse relation
+ // TODO: rethink this later as we see more 1-1 relations
+ // what we really want is to only update the inverseProp if it is dependent but we don't have Prin-Dep relns yet.
+ newValue.setProperty(inverseProp.name, this);
+ }
+ } else {
+ newValue.setProperty(inverseProp.name, this);
+ }
} else {
// navigation property change - undo old relation
if (oldValue) {

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -1514,7 +1514,7 @@ public partial class InternationalOrder {
/// <summary>Gets or sets the OrderID. </summary>
[Key]
[DataMember]
- // [ForeignKey("Order")]
+ [ForeignKey("Order")]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
[Column("OrderID")]
// [IbVal.RequiredValueVerifier( ErrorMessageResourceName="InternationalOrder_OrderID")]
@@ -1545,9 +1545,9 @@ public partial class InternationalOrder {
/// <summary>Gets or sets the Order. </summary>
[DataMember]
- [ForeignKey("OrderID")]
- [InverseProperty("InternationalOrder")]
- [Required]
+ //[ForeignKey("OrderID")]
+ //[InverseProperty("InternationalOrder")]
+ //[Required]
public Order Order { get; set; }
#endregion Navigation properties
@@ -1,7 +1,7 @@
// Only one of the next 3 should be uncommented.
-//#define CODEFIRST_PROVIDER
+#define CODEFIRST_PROVIDER
//#define DATABASEFIRST_OLD
-#define DATABASEFIRST_NEW
+//#define DATABASEFIRST_NEW
//#define NHIBERNATE
@@ -230,7 +230,11 @@ public class NorthwindIBModelController : ApiController {
return custs;
}
-
+ [HttpGet]
+ public Object CustomerCountsByCountry() {
+ return ContextProvider.Context.Customers.GroupBy(c => c.Country).Select(g => new {g.Key, Count = g.Count()});
+ }
+
[HttpGet]
public Customer CustomerWithScalarResult() {

0 comments on commit 8d9a966

Please sign in to comment.