Skip to content

Commit

Permalink
chore: fix eager load with includes
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeCisco committed Jun 30, 2021
1 parent 5478fa0 commit ebd88c5
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/helpers/forest_liana/query_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module ForestLiana
module QueryHelper
def self.get_one_associations(resource)
SchemaUtils.one_associations(resource)
.select { |association| SchemaUtils.model_included?(SchemaUtils.association_ref(association)) }
.select { |association| !SchemaUtils.polymorphic?(association) && SchemaUtils.model_included?(association.klass) }
end

def self.get_one_association_names_symbol(resource)
Expand Down
3 changes: 1 addition & 2 deletions app/serializers/forest_liana/serializer_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,7 @@ def mixpanel_integration?

SchemaUtils.associations(active_record_class).each do |a|
begin
included = SchemaUtils.model_included?(SchemaUtils.association_ref(a))
if included
if SchemaUtils.model_included?(SchemaUtils.association_ref(a))
serializer.send(serializer_association(a), a.name) {
if [:has_one, :belongs_to].include?(a.macro)
begin
Expand Down
5 changes: 1 addition & 4 deletions app/services/forest_liana/belongs_to_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ def initialize(resource, association, params)
def perform
begin
@record = @resource.find(@params[:id])
new_value = nil
if @data && @data[:id]
new_value = SchemaUtils.association_ref(@association).find(@data[:id])
end
new_value = SchemaUtils.association_ref(@association).find(@data[:id]) if @data && @data[:id]
@record.send("#{@association.name}=", new_value)

@record.save
Expand Down

0 comments on commit ebd88c5

Please sign in to comment.