Skip to content

Commit

Permalink
fix has one foreign/primary keys
Browse files Browse the repository at this point in the history
  • Loading branch information
omohokcoj committed Jul 26, 2022
1 parent 9d750ee commit f55a5b9
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/motor/build_schema/load_from_rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,18 @@ def build_action_text_column(name, model, ref)
end

def build_reference(model, name, reflection)
primary_key = reflection.polymorphic? ? 'id' : reflection.join_primary_key
foreign_key = reflection.join_foreign_key

primary_key, foreign_key = foreign_key, primary_key if reflection.has_one?

{
name: name,
display_name: model.human_attribute_name(name),
model_name: reflection.polymorphic? ? nil : reflection.klass.name.underscore,
reference_type: reflection.belongs_to? ? 'belongs_to' : 'has_one',
foreign_key: reflection.join_foreign_key,
primary_key: reflection.polymorphic? ? 'id' : reflection.join_primary_key,
foreign_key: foreign_key,
primary_key: primary_key,
options: reflection.options.slice(:through, :source),
polymorphic: reflection.polymorphic?,
virtual: false
Expand Down

0 comments on commit f55a5b9

Please sign in to comment.