Could some kind soul help a confused programmer with a stupidly simple gotcha?
I have an association like this.
Project has_and_belongs_to_many Contracts Contracts has_and_belongs_to_many Projects
I want a simple array of contracts that belong to the project. Then I want to grab each contract and merge them into the array but I dont' want them associated to the project. Here is how I did it.
<pre><code> @record = Project.first all_contracts = @record.contracts @cts = Contracts.find(:all, :limit=>5)
@cts.each do |c| all_contracts << c end </code></pre>
The issue is that the variable all_contacts is an instance of AssociationCollection instead of Array. The subsequent "<<" calls actually create the associations (which I don't want.) The only way I know of is to do the following
<pre><code> @record = Project.first all_contracts = Array.new() all_contracts = all_contracts | @record.contracts @cts = Contracts.find(:all, :limit=>5)
@cts.each do |c| all_contracts << c end </code></pre>
During the @cts.each do block, I am performing more than just adding to the all_contracts array. How do I dry up the two lines that create the all_contracts array? I want just an array, not an instance of AsociationCollection.
Thanks in advance for any help.