Opened 9 years ago

Closed 7 years ago

Last modified 7 years ago

#760 closed enhancement (duplicate)

Replace create() and update() methods with a save() method

Reported by: bergie Owned by: piotras
Priority: minor Milestone:
Component: Midgard Core Version: 9.09 Mjolnir
Keywords: activerecord Cc: indeyets@…

Description

Currently we have separate MgdSchema? API methods for creating new objects, and updating existing ones.

Instead of that, we should have a save() method that would perform the appropriate action.

Change History (11)

comment:1 Changed 9 years ago by rambo

While the shortcut could be handy (how to determine which to do, if guid is set ? how does that work with the planned ability to set guid on creation ??). In general it's important to make the distinction between create and update and I'm not quite comfortable with the idea of people who do not know which to use messing about with code.

comment:2 Changed 8 years ago by bergie

  • Priority changed from major to minor

comment:3 Changed 8 years ago by piotras

  • Milestone changed from 9.03 Vinland to 9.09 Mjolnir
  • Version changed from 9.03 Vinland to 9.09

comment:4 follow-up: Changed 8 years ago by indeyets

  • Cc indeyets@… added

I think that should be quite simple. We need to have a flag, which tells if this record originates from DB or not. Can't we use one of metadata fields for that?

If the user wants to save another copy of existing record she has to clone object. In the process of cloning this "flag" has to change its state to "not from database".

And depending on the state of this flag either "create" will issued by save or "update". Create will change the state of the flag to "from database"

comment:5 in reply to: ↑ 4 Changed 8 years ago by piotras

Replying to indeyets:

I think that should be quite simple. We need to have a flag, which tells if this record originates from DB or not.

What about object unserialized from xml file? Not real use case but still.

Can't we use one of metadata fields for that?

No, there's not such thing like property reference count available for GObject. If we talk about existing metadata. New one doesn't make sense for this purpose.

If the user wants to save another copy of existing record she has to clone object. In the process of cloning this "flag" has to change its state to "not from database".

Can you elaborate? What means "clone object"? What is the purpose of cloning? And what is the use case for cloning?

comment:6 follow-up: Changed 8 years ago by jval

Having save() is a great idea.

But sometimes applications might want to do explicitly either create of update. Removing that possibility might not be a good idea. So consider leaving create() and update() and only remove them if there's a technical good reason to do so. Adding save() is great though as that's the usual use case and it indeed helps the application writer to have it.

comment:7 in reply to: ↑ 6 Changed 8 years ago by rambo

I guess for data unserialized from XML whoever uses it must check which method to use by checking if the object exists in the databse (core could do this on unserialize but probably should not since the serialize and unserialize should work on object instances and not care about the database in any ways).

In any case it must be possible to use create and update explicitly since there are places where one must know the difference to be able to act correctly on failure (or when one knows this should be a creation and not a update or vice versa, here any magic will just introduce weird bugs).

comment:8 Changed 8 years ago by bergie

  • Milestone changed from 9.09 Mjolnir to 10.03 Ratatoskr

comment:9 Changed 7 years ago by bergie

  • Keywords activerecord added

comment:10 Changed 7 years ago by bergie

  • Resolution set to duplicate
  • Status changed from new to closed

comment:11 Changed 7 years ago by anonymous

  • Milestone 10.05.1 Ratatoskr deleted

Milestone 10.05.1 Ratatoskr deleted

Note: See TracTickets for help on using tickets.