I have to model with relation:
Participation has many Passings
In the test a got a strange thing:
participation.passings
#<ActiveRecord::Associations::CollectionProxy []>
participation.passings.to_sql
"SELECT \"passings\".* FROM \"passings\" WHERE \"passings\".\"participation_id\" = $1 ORDER BY \"passings\".\"datetime\" ASC"
But:
Passing.where(participation: participation)
#<ActiveRecord::Relation [#<Passing id: 8, chip_id: "0000001", datetime: "2016-05-05 07:28:53", detector_id: 1, event_id: 1, participation_id: 1, is_valid: false, location_id: nil, created_at: "2016-05-05 07:20:55", updated_at: "2016-05-05 07:20:55", gun_time: 0.0, split_time: 0.0, time: 0.0, raw_passing_id: 8, enabled: true>...]
I don't understand why when I call participation.passings
I get empty collection if I make query through relation model - all OK. In development environment both queries get equal result.
Aucun commentaire:
Enregistrer un commentaire