Extra query with assoc and that make app slow
ippachi opened this issue · comments
ippachi commented
class AuthorRepository < Hanami::Repository
def add_book(author, data)
assoc(:books, author).add(data)
end
end
repository = AuthorRepository.new
AuthorRepository.new.add_book(repository.first, { title: 'book title' }) # this
above code issue three query.
SELECT "id", "name" FROM "authors" ORDER BY "authors"."id" LIMIT 1
SELECT "id", "author_id", "title", "created_at", "updated_at" FROM "books" ORDER BY "books"."id"
INSERT INTO "books" ("author_id", "title", "created_at", "updated_at") VALUES (1, 'title', '2019-03-26 16:45:50.253925+0000', '2019-03-26 16:45:50.253925+0000')
I don't need second query because this make my application slow when record is increased.
Is this necessary?