I'm using sequelize module for mysql nodeJS. well, i'm creating a database to manage rabbits production in which I use this models:
var rabbit = sequelize.define('rabbit', {
name: {
type: Sequelize.STRING
},
gender: {
type: Sequelize.STRING
},
birthdate: {
type: Sequelize.DATE
},
origin: {
type: Sequelize.STRING
},
comingdate: {
type: Sequelize.DATE
},
work_group: {
type: Sequelize.BOOLEAN
}
}
);
var birth = sequelize.define('birth', {
name: {
type: Sequelize.STRING
},
fertdate: {
type: Sequelize.DATE
},
donedate: {
type: Sequelize.DATE
}
}
);
birth.hasMany(rabbit, {as: 'childOf', constraints: false});
birth.belongsTo(rabbit, {as: 'Father', constraints: false});
birth.belongsTo(rabbit, {as: 'Mother', constraints: false});
I explain: every rabbit is related to a birth in which it's born and a birth is related to two rabbits one as father and the other as mother.
The question is: what are the getters and setter, I mean if I have a rabbit object "mother" and I do mother.getBirths will it return to birth in which the mother is born or to births of which this rabbit is mother ?
And if it returns nothing or I have some errors in my code, how can I get the birth in which rabbit is born ? and how can I get births of a specified mother or father ?
thanks