Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

My associations aren't working! #23

Open
cue232s opened this issue Jun 30, 2012 · 2 comments
Open

My associations aren't working! #23

cue232s opened this issue Jun 30, 2012 · 2 comments

Comments

@cue232s
Copy link

cue232s commented Jun 30, 2012

Restaurant.populate 10..25 do |restaurant|
  restaurant.name = Populator.words(1..4).titleize
  restaurant.street_address = Faker::Address.street_address
  restaurant.description = Populator.sentences(2..8)
  restaurant.zipcode = Faker::Address.zip_code   
  restaurant.state = "MO"      
  restaurant.phone = Faker::PhoneNumber.phone_number
  Tagging.populate 6 do |tg|
    tg.restaurant_id = restaurant.id 
    tag = Tag.all
    tg.tag_id = tag[rand(tag.length)].id
  end
end

But when I go to my Tagging table, the 'restaurant_id' fields in each record is populated with an ID that is not associated with any of the Restaurant IDs that this method created. Any idea why? When I run it in Rails console, I get the desired effect.

@faddison
Copy link

Eventlog.populate 1000 do |eventlog, e_index, v_index|

    e_index = 1..Event.count
    eventlog.event_id = e_index
    eventlog.ename = Event.find_by_id(e_index).title

    v_index = 1..Visitor.count
    eventlog.visitor_id = v_index
    eventlog.vname = Visitor.find_by_id(v_index).fullname
end 

@sharpmachine
Copy link

I'm having the same issue as @cue232s. Any help would be appreciated.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants