laravel-shift/blueprint

HasMany function generation: function name has full namespaced model name instead of only model name

Closed this issue · 2 comments

  • Laravel Version: 10.39.0
  • PHP Version: 8.2.8
  • Blueprint Version: 2.9
  • Platform: Windows

Issue: Relationship function generation: function name has full namespaced model name instead of only model name

I'm working on this massive yaml file, and now I am testing out the relationships. I entered relationships for
EtimXchange\Catalogue hasMany: EtimXchange\CatalogueSupplier
EtimXchange\CatalogSuppliers belongsTo: EtimXchange\Catalogue

As a result I see the functions in the model created like so:

EtimXchange\Catalogue public function EtimXchange\CatalogueSuppliers(): HasMany {..}
EtimXchange\CatalogueSupplier public function etimXchange\Catalogue(): BelongsTo {..}

While the models are correctly namespaced : namespace App\Models\EtimXchange;

My editor squawks over the "EtimXchange" prepending the function name.

draft.yaml:

# PLEASE PASTE THE DRAFT FILE WHICH REPRODUCES THE ISSUE HERE...

models:

    

    EtimXchange\CatalogueSupplier:
        id: id
        catalogue_id: bigInteger foreign:Catalogue.id
        supplier_id: bigInteger foreign:Supplier.id
        relationships:
            belongsTo: EtimXchange\Catalogue


    EtimXchange\Catalogue:
        id: id
        catalogue_id: string:20 unique
        catalogue_name: json nullable # "CatalogueName": [{ "Language" : "(string:5)", "CatalogueName" : "(string:100)"} ,{...}]
        version: string:50 nullable
        contract_reference_number: string:20 nullable
        catalogue_type: enum:"FULL","CHANGE"
        change_reference_catalogue_version: string:50 nullable
        generation_date: date nullable
        name_data_creator: string:50 nullable
        email_data_creator: string:255 nullable
        buyer_name: string:50 nullable
        buyer_id_gln: char:13 nullable
        buyer_id_duns: char:9 nullable
        datapool_name: string:50 nullable
        datapool_gln: char:13 nullable
        catalogue_validity_start: date
        catalogue_validity_end: date nullable
        country: char:2 nullable
        language: char:5
        currency_code: char:3 nullable
        relationships: 
            hasMany: EtimXchange\CatalogueSupplier

    

Could you narrow down the draft file to only the relevant portions.

@jasonmccreary I think I found a very simple solution. And it is not a bug. Just a misconception from my side that could be clarified / explained in the documentation.
When namespacing the model, the referred model in the relationshipdefinition is already in the same namespace. Explicitly referring to the namespace like I did is redundant.
So for me this issue is solved. No need to mess up your beautiful code because of this.