weixin_39782500 2020-11-22 01:58
浏览 0

Adding a relationship to a model with a cached relationship...

If we access a relationship from a model and later on try to add a new relationship to that model we get the results of the first access of the model.

Code attached to demonstrate.

Mike.

Created by Mike (at coverallcrew) - 2009-07-06 21:28:14 UTC

Original Lighthouse ticket: http://datamapper.lighthouseapp.com/projects/20609/tickets/954

该提问来源于开源项目:datamapper/dm-core

  • 写回答

6条回答 默认 最新

  • weixin_39782500 2020-11-22 01:58
    关注

    I can confirm the above described behavior on latest next branch. However, I’m not really sure wether this is a bug or not. Another (and probably more idiomatic) way to write the above actually works as expected. (This assumes current next branch)

     ruby
    puts ’------- This works -------------------------------------’
    
    person = Person.new(:name => ’This is a person’)
    person.save
    puts "\tPerson: \t\t"        + person.inspect
    
    person.things.new(:person => person, :name => ’Something...’)
    person.save
    
    puts "\tThing:  \t\t"        + person.things.last.inspect
    puts "\tPerson’s Things: \t" + person.things.inspect
    
    person.things.new(:person => person, :name => ’Something else...’)
    person.save
    
    puts "\tThing:  \t\t"        + person.things.last.inspect
    puts "\tPerson’s Things: \t" + person.things.inspect
    

    by Martin Gamsjaeger (snusnu)

    评论

报告相同问题?