nabeelio / phpvms

virtual airline management
http://www.phpvms.net
BSD 3-Clause "New" or "Revised" License
172 stars 143 forks source link

Aircraft->Subfleet->Fare not providing capacity (Bug Report) #1555

Open FatihKoz opened 1 year ago

FatihKoz commented 1 year ago

As the title says, $pirep->aircraft->subfleet->fare is not providing the capacity with the model, but it is provided within the pivot

Version 7.0.0-dev+230621.16a31d

To Reproduce Just check the attributes of any $pirep->aircraft->subfleet->fare or check below data output

Expected behavior capacity should be there (like it is provided in the pivot)

Additional context

[2023-06-23 17:31:24] production.DEBUG: {"id":9,"code":"Y","name":"Economy","price":50,"cost":null,"capacity":null,"type":0,"notes":"1","active":true,"created_at":"2020-11-13T16:22:00.000000Z","updated_at":"2021-09-14T16:07:04.000000Z","pivot":{"subfleet_id":29,"fare_id":9,"price":null,"cost":null,"capacity":"144"}}  
[2023-06-23 17:31:24] production.DEBUG: {"id":10,"code":"J","name":"Business","price":150,"cost":null,"capacity":null,"type":0,"notes":"3","active":true,"created_at":"2020-11-13T16:22:31.000000Z","updated_at":"2021-09-14T16:04:44.000000Z","pivot":{"subfleet_id":29,"fare_id":10,"price":null,"cost":null,"capacity":"16"}}  
[2023-06-23 17:31:24] production.DEBUG: {"id":12,"code":"CGO","name":"Cargo","price":1,"cost":null,"capacity":null,"type":1,"notes":"1","active":true,"created_at":"2020-11-13T16:25:14.000000Z","updated_at":"2023-01-04T07:36:52.000000Z","pivot":{"subfleet_id":29,"fare_id":12,"price":null,"cost":null,"capacity":"6000"}}  

If this will be new default, we can just close the issue :)

arthurpar06 commented 11 months ago

Hi, While working on the new admin interface with filament, I encountered the same problem. I haven't had time to try to solve it yet but I think it's because the pivot and the main field have the same name and the main field overrides the pivot, (the main field is probably null in your case). I also had this problem with values, the main field worth 500 so I get 500 even if the pivot isn't null

nabeelio commented 11 months ago

If you call FareService::getReconciledFaresForFlight it should return the proper ones

FatihKoz commented 11 months ago

Yes, my capacities are always null in the main fare 'cause I define them at subfleet level... And I think this was (and still is) the proper way to define them.

What I am doing now is (as far as remember) instead of reading it through aircraft->subfleet->fare, I think I am reading it through pirep->fare directly, sorry I forgot how I fixed my solution, if you need I can find it though.

arthurpar06 commented 11 months ago

I'm looking into how I can get around this in a way that filaments supports... Looks like subfleet->pivot->capacity works

nabeelio commented 11 months ago

If you have the pirep, that's the correct place to read it from because it's calculated and stored

arthurpar06 commented 11 months ago

I'm not sure it's only related to pireps. I have this issue with the subfleet <> fare relationship. $subfleet->fare->capacity gives me the capacity in the fares table and not the subfleet_fare pivot

nabeelio commented 11 months ago

Yeah you have to go through the pivot, that's just how Laravel works. You can maybe add an accessor on the model which will check the pivot table, but at that point it's the call to the service, which does all the calculations

arthurpar06 commented 11 months ago

yeah actually I was a bit lost because in the filament docs they say to use only the pivot attribute name https://filamentphp.com/docs/3.x/panels/resources/relation-managers#listing-with-pivot-attributes But I found a way to make it all work I think. It may be their docs that is not accurate more than our application that is buggy.