Checking for uniqueness

J

Jason Matthew

I am using FeedTools to parse an rss feed and store it in my Meetings
model.

I am trying to store only unique parsed rss feeds. To check for
uniqueness, I have decided to use the Feed's link. How can I check if
there is not already a row in the database containing that feed's link.

require "myprogram_dbconnect"
require 'rubygems'
require 'feed_tools'

activerecord_connect

class Meeting < ActiveRecord::Base
has_many :comments
end

meeting =
FeedTools::Feed.open('http://projects.washingtonpost.com/congress/rss/committee-events/')

if #meeting with item.link does not allready exist in the database
puts "No new feeds to put in database"
else
meeting.items.each do |item|
Meeting.create:)title => item.title, :link => item.link,
:description => item.description,
:feed_data => item.feed_data, :feed_data_type =>
item.feed_data_type)
end

end
 
P

Pat Maddox

I am using FeedTools to parse an rss feed and store it in my Meetings
model.

I am trying to store only unique parsed rss feeds. To check for
uniqueness, I have decided to use the Feed's link. How can I check if
there is not already a row in the database containing that feed's link.

require "myprogram_dbconnect"
require 'rubygems'
require 'feed_tools'

activerecord_connect

class Meeting < ActiveRecord::Base
has_many :comments
end

meeting =
FeedTools::Feed.open('http://projects.washingtonpost.com/congress/rss/committee-events/')

if #meeting with item.link does not allready exist in the database
puts "No new feeds to put in database"
else
meeting.items.each do |item|
Meeting.create:)title => item.title, :link => item.link,
:description => item.description,
:feed_data => item.feed_data, :feed_data_type =>
item.feed_data_type)
end

end

You can enforce it in the model with

class Meeting < ActiveRecord::Base
has_many :comments
validates_uniqueness_of :link
end

Pat
 
J

Jason Matthew

Pat said:
You can enforce it in the model with

class Meeting < ActiveRecord::Base
has_many :comments
validates_uniqueness_of :link
end

Pat

Thanks Pat! I can't believe I didnt bother just to validate it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top