Gist 206559
✓ Published0🌍 Public
XXXX
Last edited Oct 10, 2009
Created on Oct 10, 2009
This example demonstrates a subtle bug in DataMapper, a Ruby ORM, where defining a custom `foo` method and `foo=` setter on a resource class shadows the association defined by `belongs_to`. The code creates a `Foo` and a `Bar`, then assigns the string `'boom'` to `bar.foo` and reads it back, showing that the custom setter and getter are invoked instead of the association. It uses DataMapper’s `Resource` module, `has n` and `belongs_to` macros, and `DataMapper.setup` with an in-memory SQLite database via `sqlite3::memory:`. The output is a simple string assignment and retrieval, illustrating the override behavior.
AI-generated description