#473 ✓resolved
Micah Fitch

pluralism in chained selections

Reported by Micah Fitch | July 20th, 2008 @ 03:50 PM

Story:

A chain of associations includes both has n and has 1 relationships. I would like to be able to select multiple objects from 1 to 1 relationships using plural chained selection methods.

Scenario A:

# associations
class Top
has n, :middles
end

class Middle
has 1, :bottom
belongs_to :top
end

class Bottom
belongs_to :middle
end

# chained selection to select all of the bottoms related to a top
top.middles.bottoms

Scenario B

# associations
class First
has n, :seconds
end

class Second
has n, :thirds
belongs_to :first
end

class Third
has 1 :fourth
belongs_to :second
end

class Fourth
belongs_to :third
end

# chained selection to select all of the fourths related to a first
first.seconds.thirds.fourths

Comments and changes to this ticket

  • Micah Fitch

    Micah Fitch July 20th, 2008 @ 03:55 PM

    an example script:

    require 'rubygems'
    require 'dm-core'
    
    class Top
      include DataMapper::Resource
      property :id, Serial
      has n, :middles
    end
    
    class Middle
      include DataMapper::Resource
      property :id, Serial
      belongs_to :tops
      has 1, :bottom
    end
    
    class Bottom
      include DataMapper::Resource
      property :id, Serial
      belongs_to :top
    end
    
    DataMapper.setup(:default, "sqlite3:memory:")
    DataMapper.auto_migrate!
    
    top = Top.new
    top.save
    3.times {@top.middles.create}
    top.middles.each {|r| r.bottom = Bottom.create }
    
    # this doesn't work:
    puts top.middles.bottoms.inspect
    
    # this does work but I don't know how many queries happen:
    puts top.middles.collect{|m| m.bottom}
    
  • Micah Fitch

    Micah Fitch September 7th, 2008 @ 12:04 PM

    • Title changed from “dynamic pluralism in chained selections” to “pluralism in chained selections”

    has anything been done with this?

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) November 30th, 2008 @ 01:55 PM

    • State changed from “new” to “open”

    I can confirm this is still an issue with dkubb/dm-core.

    I have attached a stand-alone script that is based on the above script.

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) December 4th, 2008 @ 03:48 AM

    • Tag changed from associations, feature, spec to associations, bug
    • State changed from “open” to “accepted”
  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) February 21st, 2009 @ 03:51 AM

    It appears as if there is an error in Micah's last example, which I missed when creating the attached file. It shows the Bottom class as belonging to the Top class, when it should be the Middle class.

    After fixing this and running it against dm-core/next, it doesn't throw an exception, but it doesn't return the expected number of rows. I believe what's happening is the Middle.has(1, :bottom) declaration is adding a LIMIT to the rows returned. Instead what should be happening is the LIMIT should be based the limit of all the relationships multiplied together.. and since the first relationship in the chain is unbounded, there should not be a LIMIT used at all.

    Attached is the updated file.

  • Dan Kubb (dkubb)

    Dan Kubb (dkubb) May 28th, 2009 @ 04:03 AM

    • State changed from “accepted” to “resolved”

    I can confirm this is resolves in dm-core/next. The file I attached earlier should return the expected rows.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

People watching this ticket

Attachments

Pages