First time here? Check out the FAQ!
Sorry, this content is no longer available
0

Why "must add revision before saving the answer"?
 

Hi

In models.post, there's the following:

    #must add revision before saving the answer
    self.add_revision(
        author = edited_by,
        revised_at = edited_at,
        text = text,
        comment = comment,
        by_email = by_email
    )

How come the revision has to be saved before the answer?

Thanks

To enter a block of code:

  • enter empty line after your previous text
  • paste or type the code
  • select the code and press the button above
Preview: (hide)
kate_r's avatar
107
kate_r
asked 11 years ago

Comments

see more comments

1 Answer

0

Not sure what your intention is. The safest approach is to use function user.post_answer(). There are also post_question() and post_comment() - those will take care of all the underlying records and will test the permissions.

If you want to follow the underlying mechanics - basically any time a foreign key relation to another object - that one has to be created first. In this case - answer object is created first, then we create the revision, because revision requires the foreign key to the answer post.

To enter a block of code:

  • enter empty line after your previous text
  • paste or type the code
  • select the code and press the button above
Preview: (hide)
Evgeny's avatar
13.2k
Evgeny
answered 11 years ago, updated 11 years ago
link

Comments

I might not be reading the code right. Isn't the revision created before the answer here? self.add_revision(..) is called before self.parse_save(..), which saves the answer object. It only doesn't crash here because the post object itself would have already been created (because it's an edit function). My point is mostly that the comment "must add revision before saving the answer" might perhaps be misleading?

kate_r's avatar kate_r (11 years ago)

That's probably in the edit function - in that case we already have the post id to use for the foreign key. In the create answer function we do this in the opposite order, see PostManager.create_new.

Evgeny's avatar Evgeny (11 years ago)

If you use functions added to the user object, you can bypass all those details (and there are more, actually).

Evgeny's avatar Evgeny (11 years ago)

Sure. Thanks for the pointers. So does that mean that comment in the edit function doesn't actually hold?

kate_r's avatar kate_r (11 years ago)

No it all works, just in the edit function we have the post, so we can safely create a revision. When we make a new post - we first make the post and then add the revision. See functions available in the askbot/models/__init__.py, added via User.add_to_class - they start at about 75% down the file.

Evgeny's avatar Evgeny (11 years ago)
see more comments