Fix bugs with relations beetwen entities