我正在使用 typeorm join 而不在表中建立关系。这是我的查询:
let query = userRepository.createQueryBuilder("u")
.where("u.academicYear = :year", { year })
.leftJoinAndMapOne("u.educationalDetails", EducationalDetails, "e", "u.id = e.userId")
.leftJoinAndMapOne("u.preferences", Preferences, "p", "u.id = p.userId")
.leftJoinAndMapOne("u.phdEducationalDetails", PhdEducationalDetails, "ep", "u.id = ep.userId")
.leftJoinAndMapOne("u.order", Order, "o", "u.serialNo = o.serialNo");
User {
id: 15,
firstName: 'moin',
lastName: 'prajapati',
nameAsOnMarksheet: 'moin prajapati',
email: '[email protected]',
mobileno: '7666126606',
dob: '2002-01-06',
gender: 'Male',
bloodGroup: 'O+',
nameAsPerAadharCard: 'mahesh prajapati',
aadharCardno: '741258369789',
corCity: 'Mumbai',
corState: 'Maharashtra',
corAddress: 'malad',
religion: 'Hinduism',
minority: 'Hindu',
corPincode: '400095',
motherName: 'mother',
fatherName: 'father',
guardianMobileno: '7666126606',
parentsMobileno: null,
admissionType: 'PHD',
admissionCategory: 'Open/General',
admissionSubCategory: 'Not Applicable',
role: 'STUDENT',
keycloakId: 'dd0cd351-0def-4490-91bc-2e8fc1e7a695',
pinPurchase: 'ugix4GviB5Bv',
status: 'ACTIVE',
serialNo: null,
registrationNo: 600005,
imagesName: null,
learningDisability: 'NOT APPLICABLE',
category: 'General',
academicYear: 2024,
registerYear: '2024',
preAddress: 'malad',
prePincode: '400095',
preCity: 'Mumbai',
preState: 'Maharashtra',
isAddressSame: 'Yes',
nationality: 'India',
familyAnnualIncome: null,
otp: null,
otpVerified: false,
otherReligion: null,
placeOfBirth: 'India',
abcId: null,
createdAt: 2024-05-04T06:00:43.423Z,
updatedAt: 2024-05-08T10:52:02.103Z,
corTaluka: null,
guardianAnnualIncome: '50,001 to 2,00,000',
employeeStatus: null,
preCountry: null,
whatsAppno: null,
isWhatsappNoSame: null,
domicileState: null,
educationalDetails: [EducationalDetails],
preferences: [Preferences],
phdEducationalDetails: null,
order: null
},
这就是我得到结果的方式。我想要这一切都在一个对象中。我们可以这样做吗?在这里我先进入数组,然后进入对象
我可以在一个对象中解决这个问题吗?我也无法使用这种关系。我想在与他们没有任何关系的情况下做到这一点
未与表建立关系时无法使用 Orm 类型连接表