mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
made persistment and hydrator to return null in properties with nullable columns; fixed tests
This commit is contained in:
parent
141a4fc52f
commit
9d0f60214e
@ -56,6 +56,9 @@ column property names and they are automatically mapped to column names
|
||||
* `SpecificRepository` has been removed. Instead new `RelationQueryBuilder` was introduced.
|
||||
* `getEntitiesAndRawResults` of `QueryBuilder` has been renamed to `getRawAndEntities`
|
||||
* in mssql all constraints are now generated using table name in their names - this is fixes issues with duplicate constraint names
|
||||
* now when object is loaded from the database all its columns with null values will be set into entity properties as null.
|
||||
Also after saving entity with unset properties that will be stored as nulls - their (properties) values will be set to null.
|
||||
Also now all
|
||||
|
||||
### DEPRECATIONS
|
||||
|
||||
|
||||
@ -10,17 +10,17 @@ export class PostDetails {
|
||||
@Column({
|
||||
nullable: true
|
||||
})
|
||||
authorName: string;
|
||||
authorName: string|null;
|
||||
|
||||
@Column({
|
||||
nullable: true
|
||||
})
|
||||
comment: string;
|
||||
comment: string|null;
|
||||
|
||||
@Column({
|
||||
nullable: true
|
||||
})
|
||||
metadata: string;
|
||||
metadata: string|null;
|
||||
|
||||
@OneToMany(type => Post, post => post.details, {
|
||||
cascadeInsert: true,
|
||||
|
||||
@ -10,17 +10,17 @@ export class PostDetails {
|
||||
@Column({
|
||||
nullable: true
|
||||
})
|
||||
authorName: string;
|
||||
authorName: string|null;
|
||||
|
||||
@Column({
|
||||
nullable: true
|
||||
})
|
||||
comment: string;
|
||||
comment: string|null;
|
||||
|
||||
@Column({
|
||||
nullable: true
|
||||
})
|
||||
metadata: string;
|
||||
metadata: string|null;
|
||||
|
||||
@ManyToMany(type => Post, post => post.details, {
|
||||
cascadeInsert: true,
|
||||
|
||||
@ -1039,6 +1039,15 @@ export class SubjectOperationExecutor {
|
||||
/*if (subject.metadata.hasTreeChildrenCountColumn) {
|
||||
subject.entity[subject.metadata.treeChildrenCountColumn.propertyName] = 0;
|
||||
}*/
|
||||
|
||||
// set values to "null" for nullable columns that did not have values
|
||||
subject.metadata.columns
|
||||
.filter(column => column.isNullable && !column.isVirtual)
|
||||
.forEach(column => {
|
||||
const columnValue = column.getEntityValue(subject.entity);
|
||||
if (columnValue === undefined)
|
||||
column.setEntityValue(subject.entity, null);
|
||||
});
|
||||
});
|
||||
|
||||
// update special columns that gets updated on each entity update
|
||||
|
||||
@ -98,7 +98,8 @@ export class RawSqlResultsToEntityTransformer {
|
||||
return;
|
||||
|
||||
column.setEntityValue(entity, this.driver.prepareHydratedValue(value, column));
|
||||
hasData = true;
|
||||
if (value !== null) // we don't mark it as has data because if we will have all nulls in our object - we don't need such object
|
||||
hasData = true;
|
||||
});
|
||||
|
||||
if (alias.metadata.parentEntityMetadata) {
|
||||
@ -108,7 +109,8 @@ export class RawSqlResultsToEntityTransformer {
|
||||
return;
|
||||
|
||||
column.setEntityValue(entity, this.driver.prepareHydratedValue(value, column));
|
||||
hasData = true;
|
||||
if (value !== null) // we don't mark it as has data because if we will have all nulls in our object - we don't need such object
|
||||
hasData = true;
|
||||
});
|
||||
}
|
||||
return hasData;
|
||||
|
||||
@ -28,6 +28,9 @@ describe("github issues > #163 ManyToMany relation : Cannot read property 'joinC
|
||||
republicCommando.searchTerms = "star-wars,shooter";
|
||||
republicCommando.isReviewed = false;
|
||||
|
||||
await connection.manager.save(battlefront);
|
||||
await connection.manager.save(republicCommando);
|
||||
|
||||
const platform = new Platform();
|
||||
platform.name = "Windows";
|
||||
platform.slug = "windows";
|
||||
|
||||
@ -3,12 +3,12 @@ import {Column} from "../../../../src/decorator/columns/Column";
|
||||
export class Duration {
|
||||
|
||||
@Column({ nullable: true })
|
||||
minutes: number;
|
||||
minutes: number|null;
|
||||
|
||||
@Column({ nullable: true })
|
||||
hours: number;
|
||||
hours: number|null;
|
||||
|
||||
@Column({ nullable: true })
|
||||
days: number;
|
||||
days: number|null;
|
||||
|
||||
}
|
||||
@ -23,10 +23,13 @@ describe("github issues > support of embeddeds that are not set", () => {
|
||||
await connection.manager.save(race);
|
||||
|
||||
const loadedRace = await connection.manager.findOne(Race, { name: "National Race" });
|
||||
expect(loadedRace).to.be.not.empty;
|
||||
expect(loadedRace!.id).to.be.not.empty;
|
||||
expect(loadedRace).to.exist;
|
||||
expect(loadedRace!.id).to.exist;
|
||||
loadedRace!.name.should.be.equal("National Race");
|
||||
expect(loadedRace!.duration).to.be.empty;
|
||||
expect(loadedRace!.duration).to.exist;
|
||||
expect(loadedRace!.duration.minutes).to.be.null;
|
||||
expect(loadedRace!.duration.hours).to.be.null;
|
||||
expect(loadedRace!.duration.days).to.be.null;
|
||||
|
||||
})));
|
||||
|
||||
|
||||
@ -281,7 +281,7 @@ describe("many-to-one", function() {
|
||||
.setParameter("id", updatedPost.id)
|
||||
.getOne();
|
||||
}).then(updatedPostReloaded => {
|
||||
updatedPostReloaded!.details.comment.should.be.equal("this is post");
|
||||
updatedPostReloaded!.details.comment!.should.be.equal("this is post");
|
||||
});
|
||||
}); // todo: also check that updates throw exception in strict cascades mode
|
||||
});
|
||||
@ -318,7 +318,7 @@ describe("many-to-one", function() {
|
||||
.setParameter("id", updatedPost.id)
|
||||
.getOne();
|
||||
}).then(updatedPostReloaded => {
|
||||
updatedPostReloaded!.details.comment.should.be.equal("this is post");
|
||||
updatedPostReloaded!.details.comment!.should.be.equal("this is post");
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -464,6 +464,8 @@ describe("many-to-one", function() {
|
||||
const expectedDetails = new PostDetails();
|
||||
expectedDetails.id = details.id;
|
||||
expectedDetails.comment = details.comment;
|
||||
expectedDetails.metadata = null;
|
||||
expectedDetails.authorName = null;
|
||||
return postDetailsRepository.findOneById(details.id).should.eventually.eql(expectedDetails);
|
||||
});
|
||||
|
||||
@ -471,6 +473,8 @@ describe("many-to-one", function() {
|
||||
const expectedDetails = new PostDetails();
|
||||
expectedDetails.id = savedDetails.id;
|
||||
expectedDetails.comment = savedDetails.comment;
|
||||
expectedDetails.metadata = null;
|
||||
expectedDetails.authorName = null;
|
||||
expectedDetails.posts = [];
|
||||
expectedDetails.posts.push(new Post());
|
||||
expectedDetails.posts[0].id = newPost.id;
|
||||
|
||||
@ -285,7 +285,7 @@ describe("many-to-many", function() {
|
||||
.setParameter("id", updatedPost.id)
|
||||
.getOne();
|
||||
}).then(updatedPostReloaded => {
|
||||
updatedPostReloaded!.details[0].comment.should.be.equal("this is post");
|
||||
updatedPostReloaded!.details[0].comment!.should.be.equal("this is post");
|
||||
});
|
||||
}); // todo: also check that updates throw exception in strict cascades mode
|
||||
});
|
||||
@ -481,6 +481,8 @@ describe("many-to-many", function() {
|
||||
const expectedDetails = new PostDetails();
|
||||
expectedDetails.id = details.id;
|
||||
expectedDetails.comment = details.comment;
|
||||
expectedDetails.metadata = null;
|
||||
expectedDetails.authorName = null;
|
||||
return postDetailsRepository.findOneById(details.id).should.eventually.eql(expectedDetails);
|
||||
});
|
||||
|
||||
@ -488,6 +490,8 @@ describe("many-to-many", function() {
|
||||
const expectedDetails = new PostDetails();
|
||||
expectedDetails.id = savedDetails.id;
|
||||
expectedDetails.comment = savedDetails.comment;
|
||||
expectedDetails.metadata = null;
|
||||
expectedDetails.authorName = null;
|
||||
expectedDetails.posts = [];
|
||||
expectedDetails.posts.push(new Post());
|
||||
expectedDetails.posts[0].id = newPost.id;
|
||||
@ -553,6 +557,8 @@ describe("many-to-many", function() {
|
||||
const details = new PostDetails();
|
||||
details.id = savedDetailsId;
|
||||
details.comment = "post details comment";
|
||||
details.metadata = null;
|
||||
details.authorName = null;
|
||||
return postDetailsRepository.findOneById(savedDetailsId).should.eventually.eql(details);
|
||||
});
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user