Code Monkey home page Code Monkey logo

has_uuid's People

Contributors

exviva avatar joergbattermann avatar norbert avatar tfe avatar troessner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

has_uuid's Issues

Using before_save and before_validation

@exviva

Right now we are using two callbacks unconditionally to generate the uuid: 6fb3387#L1R23

Back then I was ok with it, however, thinking about it now I am not so sure that we should do this anymore.

Why did we add it in the first place?

Well, apparently there is no AR callback that gets triggered before the before_validation even if we do not validate the object.
So there could (and has in our applications) arise the following cases:

a) Say we only use "before_validation"

  • We have a model which has a "validates_presence_of :uuid"
  • We sometimes need to save a model without validations
  • In this case, the model is saved but no UUID is generated

b) We only use "before_save"

  • In this case we can not use "validates_presence_of :uuid" because the validations would crash before

So, as kind of a workaround we just added both callbacks.

I think this isn't good for one reason:

Inefficiency. We're talking about adding and executing one more callback than actually necessary.

A better solution:

I think we should remove the "before_save" callback and make it prominent in the documentation: "If you do NOT validate an object, you need to manually call assign_uuid". Also, we would have to adjust our code that uses it (right now I can only think of one, possibly two places in the nucleus).

What do you think?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.