@@ -77,6 +77,11 @@ def [](index)
7777 ( @collection . length ..index ) . each do |i |
7878 new_dummy_record = ReactiveRecord ::Base . new_from_vector ( @target_klass , nil , *@vector , "*#{ i } " )
7979 new_dummy_record . attributes [ @association . inverse_of ] = @owner if @association && !@association . through_association?
80+ <<<<<<< Updated upstream
81+ =======
82+ # HMT-TODO: the above needs to be looked into... if we are a hmt then don't we need to create a dummy on the joins collection as well?
83+ # or maybe this just does not work for HMT?
84+ >>>>>>> Stashed changes
8085 @collection << new_dummy_record
8186 end
8287 end
@@ -212,7 +217,11 @@ def related_records_for(record)
212217 return [ ] unless attrs [ @association . inverse_of ] == @owner
213218 if !@association . through_association
214219 [ record ]
220+ <<<<<<< Updated upstream
215221 elsif ( source = attrs [ @association . source ] )
222+ =======
223+ elsif ( source = attrs [ @association . source ] ) && source . is_a? ( @target_klass )
224+ >>>>>>> Stashed changes
216225 [ source ]
217226 else
218227 [ ]
@@ -233,7 +242,12 @@ def live_scopes
233242 end
234243
235244 def in_this_collection ( related_records )
245+ <<<<<<< Updated upstream
236246 return related_records unless @association
247+ =======
248+ # HMT-TODO: I don't think we can get a set of related records here with a through association unless they are part of the collection
249+ return related_records if !@association || @association . through_association?
250+ >>>>>>> Stashed changes
237251 related_records . select do |r |
238252 r . backing_record . attributes [ @association . inverse_of ] == @owner
239253 end
@@ -406,7 +420,15 @@ def push_and_update_belongs_to(id)
406420 def set_belongs_to ( child )
407421 if @owner
408422 # TODO this is major broken...current
423+ <<<<<<< Updated upstream
409424 child . send ( "#{ @association . inverse_of } =" , @owner ) if @association && !@association . through_association
425+ =======
426+ if ( through_association = @association . through_association )
427+ # HMT-TODO: create a new record with owner and child
428+ else
429+ child . send ( "#{ @association . inverse_of } =" , @owner ) if @association && !@association . through_association
430+ end
431+ >>>>>>> Stashed changes
410432 elsif @parent
411433 @parent . set_belongs_to ( child )
412434 end
@@ -421,6 +443,7 @@ def set_belongs_to(child)
421443
422444 def update_child ( item )
423445 backing_record = item . backing_record
446+ <<<<<<< Updated upstream
424447 if backing_record && @owner && @association && !@association . through_association? && item . attributes [ @association . inverse_of ] != @owner
425448 inverse_of = @association . inverse_of
426449 current_association = item . attributes [ inverse_of ]
@@ -429,11 +452,44 @@ def update_child(item)
429452 if current_association && current_association . attributes [ @association . attribute ]
430453 current_association . attributes [ @association . attribute ] . delete ( item )
431454 end
455+ =======
456+ # HMT TODO: The following && !association.through_association was commented out, causing wrong class items to be added to
457+ # associations
458+ # Why was it commented out.
459+ if backing_record && @owner && @association && item . attributes [ @association . inverse_of ] != @owner && !@association . through_association?
460+ inverse_of = @association . inverse_of
461+ current_association_value = item . attributes [ inverse_of ]
462+ backing_record . virgin = false unless backing_record . data_loading?
463+ #backing_record.update_belongs_to(inverse_of, @owner)
464+ backing_record . set_belongs_to_via_has_many ( @association , @owner )
465+ # following is handled by update_belongs_to and is redundant
466+ # unless current_association_value.nil? # might be a dummy value which responds to nil
467+ # current_association = @association.inverse.inverse(current_association_value)
468+ # current_association_attribute = current_association.attribute
469+ # if current_association.collection? && current_association_value.attributes[current_association_attribute]
470+ # current_association.attributes[current_association_attribute].delete(item)
471+ # end
472+ # end
473+ >>>>>>> Stashed changes
432474 @owner . backing_record . sync_has_many ( @association . attribute )
433475 end
434476 end
435477
436478 def push ( item )
479+ <<<<<<< Updated upstream
480+ =======
481+ if ( through_association = @association &.through_association )
482+ through_association . klass . create ( @association . inverse_of => @owner , @association . source => item )
483+ self
484+ else
485+ _internal_push ( item )
486+ end
487+ end
488+
489+ alias << push
490+
491+ def _internal_push ( item )
492+ >>>>>>> Stashed changes
437493 item . itself # force get of at least the id
438494 if collection
439495 self . force_push item
@@ -449,8 +505,11 @@ def push(item)
449505 self
450506 end
451507
508+ <<<<<<< Updated upstream
452509 alias << push
453510
511+ =======
512+ >>>>>>> Stashed changes
454513 def sort! ( *args , &block )
455514 replace ( sort ( *args , &block ) )
456515 end
@@ -523,20 +582,33 @@ def internal_replace(new_array)
523582 if new_array . is_a? Collection
524583 @dummy_collection = new_array . dummy_collection
525584 @dummy_record = new_array . dummy_record
585+ <<<<<<< Updated upstream
526586 new_array . collection . each { |item | self << item } if new_array . collection
527587 else
528588 @dummy_collection = @dummy_record = nil
529589 new_array . each { |item | self << item }
590+ =======
591+ new_array . collection . each { |item | _internal_push item } if new_array . collection
592+ else
593+ @dummy_collection = @dummy_record = nil
594+ new_array . each { |item | _internal_push item }
595+ >>>>>>> Stashed changes
530596 end
531597 notify_of_change new_array
532598 end
533599
534600 def delete ( item )
535601 unsaved_children . delete ( item )
536602 notify_of_change (
603+ <<<<<<< Updated upstream
537604 if @owner && @association && !@association . through_association?
538605 inverse_of = @association . inverse_of
539606 if ( backing_record = item . backing_record ) && item . attributes [ inverse_of ] == @owner
607+ =======
608+ if @owner && @association
609+ inverse_of = @association . inverse_of
610+ if ( backing_record = item . backing_record ) && item . attributes [ inverse_of ] == @owner && !@association . through_association?
611+ >>>>>>> Stashed changes
540612 # the if prevents double update if delete is being called from << (see << above)
541613 backing_record . update_belongs_to ( inverse_of , nil )
542614 end
@@ -562,9 +634,20 @@ def loading?
562634 @dummy_collection . loading?
563635 end
564636
637+ <<<<<<< Updated upstream
565638 def loaded?
566639 false && @collection && ( !@dummy_collection || !@dummy_collection . loading? ) && ( !@owner || @owner . id || @vector . length > 1 )
567640 end
641+ =======
642+ # def loading?
643+ # !@collection || (@dummy_collection && @dummy_collection.loading?) || (@owner && [email protected] && @vector && @vector.length <= 1) 644+ # end
645+
646+ # def loaded?
647+ # @collection && (!@dummy_collection || !@dummy_collection.loading?) && (!@owner || @owner.id || !@vector || @vector.length > 1)
648+ # #false && @collection && (!@dummy_collection || !@dummy_collection.loading?) && (!@owner || @owner.id || @vector.length > 1)
649+ # end
650+ >>>>>>> Stashed changes
568651
569652 def empty?
570653 # should be handled by method missing below, but opal-rspec does not deal well
0 commit comments