We would need some more information about the model and your use case in general.
PS: you can add code snippets by wrapping it in three backticks ``` 
This would make it easier to help in debugging without rewriting your complete code.