On Jun 20, 5:18 pm, erik <[email protected]> wrote:
> I have tried this both ways and each time same results, duplicate
> entries.
>
> Here is the simple test:
> t = Trim.find(:first, :conditions => ['id > 65000000'])
> options = Option.find_all_by_trim_id(t.id)
> puts options.size
> v = NewVehicle.new({:trim_id => t.id})
> v.option_ids = options.map {|o| o.id}
> v.save
>
> I also tried it just with v.options = options, using option_ids was
> just another attempt to make this work
>
> The size of options in this case is 47.  options_vehicles which is my
> join table will have 94 results exactly 2 of each one option.  So if
> the option_id = 6 and vehicle_id is 4 i have 6,4 in the join table
> twice.
>
> I am doing one thing a little odd, but i have no idea what's causing
> this issue.  My models look like this:
> Option.rb
>  set_primary_key "option_id"
>   has_many        :options_vehicles
>   has_many        :vehicles, :through => :options_vehicles
>
> I have to use option_id as the primary key and it's a string.  This is
> other data i'm importing and I can't change the way it's organzied.
>
> Vehicle.rb
>   has_many        :options_vehicles,
>   has_many        :options, :through => :options_vehicles
>
> My join table looks like a habtm table because it was.  I have tried
> this both ways activerecord continues to put in dupes.
>
> I actually went into the code at
> /data/www/production/vendor/rails/activerecord/lib/active_record/
> associations.rb:1392
> and put prints in there and see it showing the size of the records to
> save as 47, but it's going through here twice.
>
> I have option_id in options marked as the primary key with a unique
> index in mysql.
>
> Any help would be appreciated I feel like I'm going crazy...
> Erik

You don't need to do the Options.find because you already have
t.options. This may also explain the dupes.

-eric
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
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/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to