Open ghost opened 10 years ago
anonx,
Agreed I was really not happy with the existing implementation. That's what the "@todo properly implement this" in the existing Blog.Update() controller implementation is hinting at.
Your suggestion is certainly in the direction I would like this to go and a certain improvement over where things are currently.
Goals for refactoring;
The above is just off the top of my head and I would especially like some feedback on before we agree on a direction and goals for refactoring the model handling.
@jgraham909, 1, 2, 3. Agree;
change
generation can be improved but we cannot escape the necessity to define the list of fields). If we only could get the info about form inputs and text areas (those ones which are really represented in the views source code)...
But anyway, the use of $set
instead of two separate requests to DB (See code below) is a priority number one for now, isn't it?check := models.GetArticleByObjectId(c.MongoSession, article.Id) // #1
article.Author_id = check.Author_id
article.Something = check.Something
...
article.Save(c.MongoSession) // #2
The operations are not atomic. In theory, something bad may happen in between.
Hey, Jeff.
How do you think the mechanism of saving / updating info can be improved? Now it looks like this: Model
So to use it we have to do: Controller
So in case, we add new fields to our
Article
struct like this:we have to rewrite all the fragments of updating / saving info:
to make sure that users cannot cheat the system by sending values they are not expected to.
What do you think if we change the code a little bit the following way: Model
So our controller then is:
Now we can add new fields to the
Article
structure and do not worry about a necessity to change our controller.