You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When you save (or sync) a form that has a collection, and that collection specifies a form object ItemForm, and ItemForm overrides save or sync methods, those methods are never called.
Do you think that for consistency/control that when saving/sync'ing the tree that all the Form wrappers' save/sync methods should be called, not just that of the root object?
I mentioned on gitter that I thought this was only with non-virtual collections, but it seems I misrembered and it is with any collection.
Steps to reproduce
require'rails_helper'moduleChildSaveSyncSpeccontext'saving/syncing collections with item forms'doclassSongaattr_initialize[:title]defsave(*)puts"Song.save"trueendendclassAlbumaattr_initialize[:title,:songs]do@songs=[]enddefsave(*)puts"Album.save"trueendendclassSongForm < Reform::Formproperty:titlecattr_accessor:save_count,:sync_countdefsync(*)SongForm.sync_count=SongForm.sync_count + 1puts"SongForm.sync"superenddefsave(*)SongForm.save_count=SongForm.save_count + 1puts"SongForm.save"superendendSongForm.save_count=0SongForm.sync_count=0classVirtualSongsAlbumForm < Reform::Formproperty:titlecollection:songs,virtual: true,form: SongForm,populate_if_empty: Songdefsync(*)puts"VirtualSongsAlbumForm.sync"superenddefsave(*)puts"VirtualSongsAlbumForm.save"superendendclassAlbumForm < Reform::Formproperty:titlecollection:songs,form: SongForm,populate_if_empty: Songdefsync(*)puts"AlbumForm.sync"superenddefsave(*)puts"AlbumForm.save"superendendcontext'virtual collection'doit"should run save/sync on SongForms"doform=VirtualSongsAlbumForm.new(Album.new(title: nil,songs: []))form.songs=[]form.validate("title"=>"album with virtual songs","songs_attributes"=>{"0"=>{"title"=>"bob"},"1"=>{"title"=>"song-top"},})expect{form.save}.tochange{SongForm.sync_count}.by(2).and(change{SongForm.save_count}.by(2))expect{form.sync}.tochange{SongForm.sync_count}.by(2)endendcontext'non virtual collection'doit"should run save/sync on SongForms"doform=AlbumForm.new(Album.new(title: nil,songs: []))form.validate("title"=>"album with non virtual songs","songs_attributes"=>{"0"=>{"title"=>"bob"},"1"=>{"title"=>"song-top"},})expect{form.save}.tochange{SongForm.sync_count}.by(2).and(change{SongForm.save_count}.by(2))expect{form.sync}.tochange{SongForm.sync_count}.by(2)endendendend
Expected behavior
I'd expect the specs to pass and print the following:
I'm kinda desperate for a workaround for this short of ignoring Reform#save and rewriting save logic for the whole object graph myself. Is there perhaps a way to customize the Twin objects used behind the scenes to only save when some property is true?
Complete Description of Issue
When you save (or sync) a form that has a collection, and that collection specifies a form object
ItemForm
, andItemForm
overridessave
orsync
methods, those methods are never called.Do you think that for consistency/control that when saving/sync'ing the tree that all the Form wrappers'
save/sync
methods should be called, not just that of the root object?I mentioned on gitter that I thought this was only with non-virtual collections, but it seems I misrembered and it is with any collection.
Steps to reproduce
Expected behavior
I'd expect the specs to pass and print the following:
Actual behavior
specs fail, and following is printed:
System configuration
Reform version: 2.3.0.rc1
Full Backtrace of Exception (if any)
The text was updated successfully, but these errors were encountered: