sql - Ruby on Rails: Duplicates with Join -


i working on part of app sort list of children based on parent's other children's attributes.

here classes i'm working with:

class specialchild   belongs_to: parent  class child_a   belongs_to: parent  class child_b   belongs_to: parent  class parent   has_many: specialchild   has_many: child_a   has_one: child_b 

these 2 order functions applied it:

scope :order_child_a,   joins("inner join child_a on specialchild.parent_id = child_a.parent_id").   where("booleanvalue = true")  scope :order_parent_and_child_b,   joins("left outer join parent on specialchild.parent_id = parent.id").   joins("left outer join child_b name on parent.child_b_id = child_b.id").   order("name asc, parent.lastname asc") 

my problem though there 1 specialchild in list yet parent has multiple child_a's have booleanvalue = true, copies of same specialchild showing if doesn't exist.

edit: problem arises in first scope though included second 1 because cannot .uniq without hitting more errors because of missing expected information. avoid modifying order_parent_and_child_b used throughout entire app.

i don't know if understand correctly maybe can avoid issue specifying name of table inside clause, this:

scope :order_child_a,   joins("inner join child_a on specialchild.parent_id = child_a.parent_id").   where("specialchild.booleanvalue = true") 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -