Hi,

I have 2 models as follows:

class IexRecord < Sequel::Model(DB_SQLITE)
  one_to_many :eligibility_data, :key => :source
  #Note: the original primary in the table was :id, but I set it to :source 
in other to get the Many-to-One association filter to work.
  set_primary_key :source
end

class EligibilityDatum < Sequel::Model(DB_SQLITE)
  many_to_one :iex_record, :key => :source
end

When I do a filtering on the many-to-one model, it works fine.
pp @eligibility_data
#<EligibilityDatum @values={:id=>109585, :source=>"1012293073"}>

@eligibility_data.iex_record_dataset
#<Sequel::SQLite::Dataset: "SELECT * FROM `iex_records` WHERE 
(`iex_records`.`source` = '1012293073') LIMIT 1">



But if I do this the other way around (filtering on one-to-many)
pp @iex_record
#<IexRecord @values={:id=>3073, :source=>"1012293073"}>

@iex_record.eligibility_data_dataset
#<Sequel::SQLite::Dataset: "SELECT * FROM `eligibility_data` WHERE 
(`eligibility_data`.`source` = 3073)">

The problem is on "eligibilty_data.source = 3073"

Instead of filtering by the "source" value (1012293073), it's filtering by 
the "id" value (3073).
In the IexRecord model, I tried "set_primary_key :source" but it doesn't 
help.

What is the correct way to define my model so that the association 
filtering will use "source" instead of "id"?

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sequel-talk/-/-cZ48g_8lOMJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to