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

Issue with custom primary keys #2

Open
SuperSeb92 opened this issue Jan 6, 2016 · 3 comments
Open

Issue with custom primary keys #2

SuperSeb92 opened this issue Jan 6, 2016 · 3 comments

Comments

@SuperSeb92
Copy link

When using a custom primary key in a model

protected $primaryKey = 'reference';

and the following migration

        $table->string('reference', 20)->primary();
        $table->string('parent_id', 20)->nullable();
        $table->integer('lft')->nullable();
        $table->integer('rgt')->nullable();
        $table->integer('depth')->nullable();

The following:

    $things = [
          ['reference' => 'One'],
          [
               'reference' => 'Two',
               'children' => [
                    ['reference' => 'TwoDotOne'],
                    ['reference' => 'TwoDotTwo']
                 ]
          ],
          ['reference' => 'Three']
     ];
     App\Thing::buildTree($things);

results in a "No query results for model" Error, triggered by the $self->reload() in Node@setDepth.

I guess this is because we're reloading before the new model is persisted?

@gazsp
Copy link
Owner

gazsp commented Jan 6, 2016

You're right about the call to reload, but I'm not sure why this only affects models with a custom primary key.

Could you write a failing unit test + migration to demonstrate the issue please? If you fork the repo and make a pull request, I can then take a look. Thanks.

@ArbnorZeqiri
Copy link

I'm having similar problem with similar migration.

When I want to save a model that value of custom primary key is float number, then results in a "No query results for model" Error, triggered by the $self->reload() in Node@setDepth, but model is saved in database.

When the value of custom primary key has at least one non-numeric character, then it works well.

@ArbnorZeqiri
Copy link

Hey, I found the solution.

try setting $incrementing = false in your model.

That worked for me.

algorhythm referenced this issue in dogado-group/baum Jul 18, 2017
Update InstallCommand.php For Laravel 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants