Giter Site home page Giter Site logo

Comments (9)

drewclauson avatar drewclauson commented on June 2, 2024

I would find that useful, as I'm manually checking for that scenario in several cases at this point. An exception would be easier to handle IMHO.

from doctrine-specification.

Nyholm avatar Nyholm commented on June 2, 2024

Thank you for this suggestion. I like the idea.
If I'm not misremembering there are a way of achieving this. Does the behavior for matchOne differ from using the following?

// Will throw a NoResultException if nothing found
$oneResult = $repo->match(Spec::andX(
  new MySpec(),
  Spec::limit(1)
), Spec::asSingle());

from doctrine-specification.

adamquaile avatar adamquaile commented on June 2, 2024

I didn't know about that. That would do the trick, except that AsSingle uses Query::HYDRATE_SINGLE_SCALAR so it throws a Doctrine\ORM\NonUniqueResultException for objects.

Changing the hydration mode would be a BC breaking change. Perhaps Spec::asSingle(AsSingle::OBJECT), but then the API is starting to look a bit untidy. What are your thoughts?

from doctrine-specification.

Nyholm avatar Nyholm commented on June 2, 2024

Lets introduce Spec::asSingleScalar and rewrite Spec::asSingle. Would that work?
Please send a PR if you want to.

from doctrine-specification.

adamquaile avatar adamquaile commented on June 2, 2024

Yes, that would work. Would you also want matchOne as syntactic sugar for Spec::asSingle, or just the one method?

from doctrine-specification.

Nyholm avatar Nyholm commented on June 2, 2024

Im not too sure if about introducing matchOne on the EntitySpecificationRepositoryTrait. I want to try to solve problems using Specifications.

from doctrine-specification.

adamquaile avatar adamquaile commented on June 2, 2024

Okay, no problem.

from doctrine-specification.

Nyholm avatar Nyholm commented on June 2, 2024

Fixed by #113

from doctrine-specification.

Nyholm avatar Nyholm commented on June 2, 2024

I've tagged version 0.6.1 which includes this feature.

from doctrine-specification.

Related Issues (20)

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.