Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-3160

Maybe a belongs_to subclasses problem

    • Type: Icon: Task Task
    • Resolution: Cannot Reproduce
    • Priority: Icon: Major - P3 Major - P3
    • 5.0.1
    • Affects Version/s: None
    • Component/s: None
    • None

      Hi all,
      I have this situation:

      class Event
        include Mongoid::Document
        include Mongoid::Spacial::Document
        include Mongoid::MultiParameterAttributes
        include Mongoid::Timestamps
      
        belongs_to :ordered_event_subscription
      
        ...
      
      class OrderedEventSubscription < OrderedSubscription
        include Mongoid::Document
      
        has_many :events
      
        ...
      
      class OrderedTimeEventSubscription < OrderedEventSubscription
        include Mongoid::Document
      
        ...
      

      If I have an event with an OrderedEventSubscription associated, all works like a charm, like this:

      1.9.3p327 :003 > e = Event.first
       => #<Event _id: 519f593c1d41c87e39000003, created_at: 2013-05-24 12:12:44 UTC, updated_at: 2013-06-22 13:15:29 UTC, title: "test", description: "fdsadsfa", address: "Via Roma, 12, 35027 Noventa PD, Italia", start_date: 2013-07-24 14:00:00 UTC, end_date: 2013-07-30 14:00:00 UTC, tag: "", entrance_fee: "", phone: "", email: "", visibility_date: 2013-05-10 14:00:00 UTC, coordinates: [11.952121900000066, 45.415653], local_name: "", last_push: 2013-06-22 00:00:00 UTC, category_ids: ["51837b2f1d41c843c6000004"], flyer_id: "519f59281d41c85b48000002", ordered_event_subscription_id: "519f3d611d41c81645000001", creator_id: "519f2ebe1d41c84207000002"> 
      1.9.3p327 :004 > e.ordered_event_subscription = OrderedEventSubscription.first
       => #<OrderedEventSubscription _id: 51837b631d41c842ac000004, created_at: 2013-05-03 08:54:59 UTC, updated_at: 2013-05-03 08:54:59 UTC, paid: true, usage: 0, total_number: 10, price: 0.0, user_id: "51837b631d41c842ac000002", _type: "OrderedEventSubscription", visibility_days: 14> 
      1.9.3p327 :005 > e.save
      [paperclip] Saving attachments.
       => true 
      1.9.3p327 :006 > e.ordered_event_subscription
       => #<OrderedEventSubscription _id: 51837b631d41c842ac000004, created_at: 2013-05-03 08:54:59 UTC, updated_at: 2013-05-03 08:54:59 UTC, paid: true, usage: 0, total_number: 10, price: 0.0, user_id: "51837b631d41c842ac000002", _type: "OrderedEventSubscription", visibility_days: 14> 
      

      But if I associate an OrderedTimeEventSubscription this happens

      1.9.3p327 :013 > e = Event.first
       => #<Event _id: 519f593c1d41c87e39000003, created_at: 2013-05-24 12:12:44 UTC, updated_at: 2013-07-12 11:17:51 UTC, title: "test", description: "fdsadsfa", address: "Via Roma, 12, 35027 Noventa PD, Italia", start_date: 2013-07-24 14:00:00 UTC, end_date: 2013-07-30 14:00:00 UTC, tag: "", entrance_fee: "", phone: "", email: "", visibility_date: 2013-05-10 14:00:00 UTC, coordinates: [11.952121900000066, 45.415653], local_name: "", last_push: 2013-06-22 00:00:00 UTC, category_ids: ["51837b2f1d41c843c6000004"], flyer_id: "519f59281d41c85b48000002", ordered_event_subscription_id: "51837b631d41c842ac000004", creator_id: "519f2ebe1d41c84207000002"> 
      1.9.3p327 :014 > e.ordered_event_subscription = OrderedTimeEventSubscription.first
       => #<OrderedTimeEventSubscription _id: 519f3d611d41c81645000001, created_at: 2013-05-24 10:13:53 UTC, updated_at: 2013-07-12 10:58:15 UTC, paid: true, usage: 2, total_number: 123456789, price: 99.9, user_id: "519f2ebe1d41c84207000002", _type: "OrderedTimeEventSubscription", visibility_days: 14, expiration_date: 2014-05-24 10:13:53 UTC> 
      1.9.3p327 :015 > e.save
      [paperclip] Saving attachments.
       => true 
      1.9.3p327 :016 > e.ordered_event_subscription
       => #<OrderedTimeEventSubscription _id: 519f3d611d41c81645000001, created_at: 2013-05-24 10:13:53 UTC, updated_at: 2013-07-12 10:58:15 UTC, paid: true, usage: 2, total_number: 123456789, price: 99.9, user_id: "519f2ebe1d41c84207000002", _type: "OrderedTimeEventSubscription", visibility_days: 14, expiration_date: 2014-05-24 10:13:53 UTC> 
      1.9.3p327 :017 > reload!
      Reloading...
       => true 
      1.9.3p327 :018 > e = Event.first
       => #<Event _id: 519f593c1d41c87e39000003, created_at: 2013-05-24 12:12:44 UTC, updated_at: 2013-07-12 11:19:12 UTC, title: "test", description: "fdsadsfa", address: "Via Roma, 12, 35027 Noventa PD, Italia", start_date: 2013-07-24 14:00:00 UTC, end_date: 2013-07-30 14:00:00 UTC, tag: "", entrance_fee: "", phone: "", email: "", visibility_date: 2013-05-10 14:00:00 UTC, coordinates: [11.952121900000066, 45.415653], local_name: "", last_push: 2013-06-22 00:00:00 UTC, category_ids: ["51837b2f1d41c843c6000004"], flyer_id: "519f59281d41c85b48000002", ordered_event_subscription_id: "519f3d611d41c81645000001", creator_id: "519f2ebe1d41c84207000002"> 
      1.9.3p327 :019 > e.ordered_event_subscription
       => nil 
      

      You can notice that if I make another query against event and inspect the ordered_event_subscription association property it's return null

      I'm not saying that it's a bug, but how can I resolve this issue?

      Thanks!

            Assignee:
            emily.stolfo Emily Stolfo
            Reporter:
            andreabeggiato-geekcups andreabeggiato-geekcups
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: