Giter Club home page Giter Club logo

Comments (8)

milesj avatar milesj commented on June 27, 2024

How so? Number 4 wouldn't generate "abc-1" as "abc" doesn't exist, it would stay as "abc".

from utility.

dilab avatar dilab commented on June 27, 2024

Because you are using LIKE to check the slug.

So the conditions is [slug LIKE] => 'abc%'. Which will return count as 1.

That is how you get 'abc-1' at the Number 4.

Hope it is clear.

from utility.

milesj avatar milesj commented on June 27, 2024

I'll have to change the LIKE logic then, because I guess "abcd" will also trigger it.

from utility.

milesj avatar milesj commented on June 27, 2024

Rewrote the queries.

from utility.

dilab avatar dilab commented on June 27, 2024

This will not work.

For example:

  1. abc -> abc
  2. abc -> abc-1($count=1)
  3. abc -> abc-1($conditions['slug']='abc', $count=1 && $conditions['slug'] = 'LIKE abc-%', $count=1)

You will see point 2 and 3 are producing the same slug.

Why do not you just use a while loop to check the uniqueness of the slug?

from utility.

milesj avatar milesj commented on June 27, 2024

It runs 2 queries, so if our slug was abc.

1st query - If abc does not exist, then abc is the slug, else...
2nd query - Do a wildcard search for abc-%, which will return slug as abc-#.

The queries aren't doing an &&, they are 2 separate queries.

from utility.

dilab avatar dilab commented on June 27, 2024

My point 3 is saying:

1st query: abc exists, and $count = 1 , so continue to 2nd query
2nd query: it only check abc-%, which will return $count = 1 again. Which generates a slug with value of 'abc-1'.

You see the problem here? point 2 and 3 are producing the same slug.

from utility.

milesj avatar milesj commented on June 27, 2024

I just need to fix that if statement, one sec.

from utility.

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.