Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assigning associations to a model automatically persists that model to the table. #173

Open
moniecodes opened this issue Jan 23, 2014 · 0 comments

Comments

@moniecodes
Copy link

Hey guys,

I already saw a ticket about belongs_to assignment auto saving the record, but this seems to happen when any association is assigned.

Our dynamoid models double as both serializable and display object. However, if we create a model on the fly and assign associations to it, that model is auto saved, though we don't want it to be.

In the example below, if i don't create the position associations, then the "widget" is not persisted. If I do, it is. This is a big issue for us, as it definitely affects performance, but also makes our dynamoid models not very reusable.

Thanks for the help on this!

eg:

      widgets = ArchiveLoader.get_all_widgets;
      if widgets
        widgets.each do |w|
          widget = Display::Widgets::Base.create(:name => w.name)
          w.positions.each do |pos|
            #widget and position are auto saved with this line
            position = widget.positions.create(:module => pos.module)
          end
          result << widget
        end
      end
    end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant