Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>So my other answer helped me do what i needed to do; however, i was needing to basically go one level of associations deeper and i was hitting walls with that solution. I ended re-reading the FactoryGirl documentation for associations and came up with this solution that works in all my cases. It creates songs, song_arrangements, and song_arrangement_files. I'm sure the code isn't pretty, but it works and can be improved upon later. Hope this helps anyone running into the same type of roadblocks.</p> <pre><code>FactoryGirl.define do factory :song do |s| s.sequence(:title) { |n| "Song Title #{n}" } s.sequence(:artist) { |n| "Song Artist #{n}" } factory :song_with_song_arrangements do ignore do song_arrangements_count 100 end after(:create) do |song, evaluator| FactoryGirl.create_list(:song_arrangement, evaluator.song_arrangements_count, song: song) end end end factory :song_arrangement do |sa| song sa.sequence(:title) { |n| "Arrangement #{n}" } original_key 'A' bpm 75 sa.sequence(:chart_content) { |n| "This is the chart content for Arrangement #{n}." } chart_mapping 'V1, C, V2, C, B, C, C' sa.sequence(:notes) { |n| "These are notes for the Arrangement #{n}." } factory :song_arrangement_with_song_arrangement_files do ignore do song_arrangement_files_count 100 end after(:create) do |song_arrangement, evaluator| FactoryGirl.create_list(:song_arrangement_file, evaluator.song_arrangement_files_count, song_arrangement: song_arrangement) end end end factory :song_arrangement_file do |saf| song_arrangement song saf.sequence(:title) { |n| "Attachment #{n}" } url 'http://www.google.com' saf.sequence(:description) { |n| "This is the description of Attachment #{n}." } end end </code></pre> <p>Code used to call these factories:</p> <pre><code>Songs: before(:each) { FactoryGirl.create_list(:song, 25) } Song Arrangements: before(:each) { FactoryGirl.create(:song_with_song_arrangements) } Song Arrangement Files: before(:each) { FactoryGirl.create(:song_arrangement_with_song_arrangement_files) } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload