Skip to content

Added fix to hasOne relationship #30

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/ModelCore.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

//Making possible to instance the typeof ModelCore
var ModelCore = function ModelCore(settings) {
this.$init.apply(this, arguments);
ModelCore.prototype.$init.apply(this, arguments);
};

//Making the magic happens
Expand Down Expand Up @@ -164,7 +164,7 @@
//search for many to many or one to many
for(var rel in self.$hasMany) {
if(rel === name) {
self[rel] = new self.$mapping[rel]();
self[rel] = new self.$mapping[rel];
query = query || {};

for(var i in self.$hasMany[rel]) {
Expand All @@ -178,10 +178,10 @@
//search for one to one
for(var rel in self.$hasOne) {
if(rel === name) {
self[rel] = self.$mapping[rel]();
self[rel] = new self.$mapping[rel];

var id = self[self.$hasMany[rel].id]; //mandatory
var field = self.$hasMany[rel].field || null;
var id = self[self.$hasOne[rel].id]; //mandatory
var field = self.$hasOne[rel].field || null;

return self[rel].$get(id,field);
}
Expand Down