Rewrite hasOne, hasMany, ref. Fix a lot of bugs