mongoid/mongoid — Issue #1347: find_or_create_by problem with embedded 1 to n and Hashes
Author: bcassell
Created: 2011-10-13 19:12:53+00:00
State: open

I have an embedded 1 to many relationship that looks like the following:

```ruby
class A
include Mongoid::Documents
embeds_many :bs
end

class B
embedded_in :a
field :h, type: Hash
end
```

When I call the following:

```ruby
a = A.new
a.bs.find_or_create_by(h: {key: "value"})
a.bs.find_or_create_by(h: {key: "some other value"})
```

the first call is successful, but the second call gives me:

```ruby
NoMethodError: undefined method `new' for nil:NilClass
```