hi steven,
this is what i know,
in your feed model i guess there is a association defined, with
"items" as name of association,
so when ever you do some thing like feed.items = {Some Item Objects}
that will be associated to
this feed db object(row). (i don''t know whether you can override this
behaviour)
So, in this case if do this it works fine,
class Feed < ActiveRecord::Base
attr_accesor :related_tmp_items # just name sake
has_many :items
def initialize(*args)
super(*args)
@related_tmp_items=nil
end
end
now if i say something like this,
feed.related_tmp_items = Item.find() # find what ever i want..
Note:
One more way is ( i din''t try this), using Transaction::Simple..
using that you can start your transaction before items are assigned
and rollback the transaction when you don''t want.
You may face same problem if you try something like this.
feed.item_ids = {list of item object id''s}.. # basically many to many
relation-ship
P.s: Sorry if i am not answering your problem statement.
On Sep 10, 4:22 pm, Steven Shingler
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:> Hi all,
>
> In this bit of code:
>
> @feeds = Feed.find_all
> @feeds.each { |feed|
> items = []
> rssdoc = Hpricot.XML(open(feed.url, ''User-Agent''
=> USER_AGENT))
> (rssdoc/:item).each {|item| items.push(rss_item_to_db_item(item,
> @query.id))}
> feed.items = items
>
> }
>
> Feed is an Active Record database object, as is Item.
>
> So I''m looping through each Feed object, and getting an array of
items
> back.
>
> The Item objects are being persisted in the database when I assign the
> array to the feed.items object.
>
> I didn''t expect that to happen! Could anyone tell me why it is
happening
> please?! :)
>
> Many Thanks,
> Steven
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---