laravel-shift / blueprint

A code generation tool for Laravel developers.
MIT License
2.82k stars 270 forks source link

issue with Model Keys and Indexes #650

Closed devhoussam1998 closed 9 months ago

devhoussam1998 commented 9 months ago

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
jasonmccreary commented 9 months ago

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.

devhoussam1998 commented 9 months ago

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');
}
jasonmccreary commented 9 months ago

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.