-
Notifications
You must be signed in to change notification settings - Fork 324
Open
Description
if association data already exists for a resource, using the build method doesn't append the new item to the list
Her::API.setup :url => "https://api.example.com" do |builder|
builder.use Her::Middleware::FirstLevelParseJSON
builder.use Faraday::Request::UrlEncoded
builder.adapter :test do |stub|
stub.get("/users/1") { |env| [200, {}, { :id => 1 }.to_json] }
stub.get("/users/1/comments") { |env| [200, {}, [{ :id => 1, :body => "Hello!", :user_id => 1 }].to_json] }
end
end
class User
include Her::Model
has_many :comments
end
class Comment
include Her::Model
belongs_to :user
end
user = User.find(1) # => #<User(users/1) id=1>
user.comments # => [#<Comment(comments/1) body="Hello!" user_id=1 id=1 user=#<User(users/1) id=1>>]
user.comments.build(:body => "Cool!") # => #<Comment(comments) body="Cool!" user_id=1>
user.comments # => [#<Comment(comments/1) body="Hello!" user_id=1 id=1 user=#<User(users/1) id=1>>] Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels