Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature - do not use ids as keys #2

Open
alexiswbr opened this issue Dec 17, 2015 · 3 comments
Open

feature - do not use ids as keys #2

alexiswbr opened this issue Dec 17, 2015 · 3 comments

Comments

@alexiswbr
Copy link

Hello, thank you for sharing your work.
Is there any way to do not use id's rows as key ? I tried but I did not achieved it.

@afilina
Copy link
Owner

afilina commented Dec 17, 2015

I don't understand exactly what you're trying to achieve. Can you give me an example SQL and resulting array that you want?

@alexiswbr
Copy link
Author

Imagine you are in a Forum Home. Each of the forums are joined with the last post in a thread. My SQL request looks like this pseudo code:

SELECT f.id AS forum__id,
    f.name AS forum__name,
    t.id AS forum__thread__id,
    t.name AS forum__thread__name,
    p.id AS forum__thread__post__id,
    p.author AS forum__thread__post__author

I get an array, which is correctly sorted. But the keys are the ids of the rows in my database. For example :

array
    1 =>
      object(ForumEntity)
        protected 'id' => '1'
        protected 'name' => 'foo'
        public 'thread'
            array
                3 =>
                  object(ThreadEntity)
                    protected 'id' => '3'
                    protected 'name' => 'hello'
                    public 'post'
                        array
                            5 =>
                              object(PostEntity)
                                protected 'id' => '5'
                                protected 'name' => 'mario'
    2 =>
      etc...
    7 =>
      etc...

As you can see, the ids are obviously not following on each other.
In my case, I need the keys to be incremented : 0,1,2,3..., like a classical array, regardless of the ids.

array
    0 =>
      object(ForumEntity)
        protected 'id' => '1'
        protected 'name' => 'foo'
        public 'thread'
            array
                0 =>
                  object(ThreadEntity)
                    protected 'id' => '3'
                    protected 'name' => 'hello'
                    public 'post'
                        array
                            0 =>
                              object(PostEntity)
                                protected 'id' => '5'
                                protected 'name' => 'mario'
    1 =>
      etc...
    2 =>
      etc...

Sorry for the long post, I hope my explanations are clear.

@afilina
Copy link
Owner

afilina commented Jan 27, 2016

Ah yes, that makes sense. I'll try to fix it on the plane.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants