I'm using the dataset API to build my query, and after I want to fetch the 
models. Problem is, as the join is retrieving multiple rows per parent 
table row (not in itself a SQL problem), this is being translated into the 
same model being repeatedly returned. Here's an example:


require 'sequel'
require 'logger'

DB = Sequel.sqlite
DB.loggers = [Logger.new(STDOUT)]

DB.create_table? :cars do
  primary_key :id
end
DB.create_table? :wheels do
  foreign_key :car_id, :cars
  column :number, Integer
  column :brand, String
end

class Car < Sequel::Model
  one_to_many :wheels
end

class Wheel < Sequel::Model
  many_to_one :car
end

  car = Car.create
  car.add_wheel brand: "Wolkswagen", number: 1
  car.add_wheel brand: "Wolkswagen", number: 2
  car.add_wheel brand: "Wolkswagen", number: 3
  car.add_wheel brand: "Wolkswagen", number: 4
  car2 = Car.create
  car2.add_wheel brand: "Mitsubishi", number: 1
  car2.add_wheel brand: "Mitsubishi", number: 2
  car2.add_wheel brand: "Mitsubishi", number: 3
  car2.add_wheel brand: "Mitsubishi", number: 4


puts Car.join(:wheels, :cars__id => :wheels__car_id).all.map(&:id).inspect

DB.drop_table :wheels, :cars

I know that the inner join thing is not doing anything, but in my real 
world example, I'm using it to filter by some column in the second table. 

Something like [1, 1, 1, 1, 2, 2, 2, 2] will come out. I consider this 
wrong, as the query should uniquely return only 2 Car instances. Is this a 
bug or expected behaviour? and how should I mitigate it? 



-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to