# Checking for uniqueness

**URL:** <https://www.ruby-forum.com/t/checking-for-uniqueness/120601>\
**Category:** Ruby\
**Created:** [November 19, 2007, 3:18am UTC](https://www.ruby-forum.com/t/checking-for-uniqueness/120601 "2007-11-19T03:18:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jasonmorrison](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/47e85d/32.png) [@jasonmorrison](https://www.ruby-forum.com/u/jasonmorrison)\
**Post date:** [November 19, 2007, 3:18am UTC](https://www.ruby-forum.com/t/checking-for-uniqueness/120601/1 "2007-11-19T03:18:37Z")

</div>

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/](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

---

<div class="post-metadata">

**Author:** ![jasonmorrison](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/47e85d/32.png) [@jasonmorrison](https://www.ruby-forum.com/u/jasonmorrison)\
**Post date:** [November 19, 2007, 4:28am UTC](https://www.ruby-forum.com/t/checking-for-uniqueness/120601/2 "2007-11-19T04:28:31Z")

</div>

On Nov 18, 2007 6:18 PM, Jason M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> puts "No new feeds to put in database"
> 
> ```
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

You can enforce it in the model with

class Meeting \< ActiveRecord::Base  
has\_many :comments  
validates\_uniqueness\_of :link  
end

Pat

---

<div class="post-metadata">

**Author:** ![jasonmorrison](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/47e85d/32.png) [@jasonmorrison](https://www.ruby-forum.com/u/jasonmorrison)\
**Post date:** [November 19, 2007, 4:44am UTC](https://www.ruby-forum.com/t/checking-for-uniqueness/120601/3 "2007-11-19T04:44:52Z")

</div>

Pat M. wrote:

> On Nov 18, 2007 6:18 PM, Jason M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > ```
> > puts "No new feeds to put in database"
> > 
> > ```
> > 
> > Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> 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.
