laravel-shift/blueprint

issue with Model Keys and Indexes

devhoussam1998 opened this issue · 3 comments

  • Laravel Version: ^10.10
  • PHP Version: ^8.1
  • Blueprint Version: ^2.7
  • Platform: Mac

Issue:

first of all I did not find any way to communicate I can't send a message on twitter and there is no Discussions that's why I add my question here

parent_id: foreign:page.parents.id

What I get:

public function page(): BelongsTo
{
  return $this->belongsTo(Page::class, 'parent_id', 'parents');
}

expected result:

public function parent(): BelongsTo
{
  return $this->belongsTo(Page::class, 'parent_id');
}

draft.yaml:

models:
  Page:
    title: string index
    slug: string unique
    layout: default:default index
    blocks: json
    parent_id: foreign:pages nullable onUpdate:cascade onDelete:cascade

I don't think a double nested dot syntax is supported. Have you tried without it? It doesn't seem to me it's necessary.

public function parent(): BelongsTo
{
return $this->belongsTo(Page::class, 'parent_id');
}

How I can achieve

expected result:

public function parent(): BelongsTo
{
  return $this->belongsTo(Page::class, 'parent_id');
}

Sorry, I don't understand your reply. I think if you simply write parent_id: foreign:Page it should work. However, Blueprint is about conventions. So it may not have syntax for naming the relationship something unconventional.

You could try setting the column to something else, like unsigned bigInt then setting the belongsTo relationship. Again, there are a few different ways to set relationships. One of them may get you what you need. But if not it's an easy enough change to do yourself.