hyperstack-org / hyperstack-org/hyperstack

Missing inverse of has_many :though not detected

Offen
#298 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
bug
Vorherrschende Sprache
JavaScript
Sterne
538
Forks
41
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

consider

```ruby
class Physician < ActiveRecord::Base
has_many :appointments
has_many :patients, through: :appointments
end

class Appointment < ActiveRecord::Base
belongs_to :physician
belongs_to :patient
end

class Patient < ActiveRecord::Base
has_many :appointments
has_many :physicians, through: :appointments
end
```

now if we define `Physician#patients` as `has_many :patients` (i.e. without the through) and then do this:

```ruby
old_physician = Physician.find_by_name('Foo')
new_patient = Patient.new(name: 'new guy')
appt = Appointment.new(physician: old_physician, patient: new_patient)
```

we would find on the server that

```ruby
new_patient.physicians
```

is `[]`

but on the client the list is empty. So it seems that Rails is inferring (or not even caring about) the missing inverse `has_many though:` on `Physician` (since we are not accessing it), but hyperstack is failing for some reason.

Of course if we can infer the relationship (per Rails) that is great, but at least there should be a warning or error so you can fix it.

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.