Forum: Ruby on Rails habtm :uniq causing duplicate inserts? How to update Rails?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
softwareengineer 99 (Guest)
on 2006-02-07 18:39
(Received via mailing list)
Hello *Gem* experts,

  Sorry for asking multiple questions in one post but they are both
related to one problem.

  So far I have the following code:

  class Member < ActiveRecord::Base
       has_and_belongs_to_many :blogs, :uniq=>true
  .....
  end

  class Blog < ActiveRecord::Base
       has_and_belongs_to_many :members,  :uniq=>true
  ...
  end

  The issue is that :uniq=> true isn't working and multiple records  are
being inserted in blogs_members table when I call the following in
Member class:

    def self.create_subscription(member, blog)
      member.blogs.push_with_attributes(blog, :created_at => Time.now)
    end

  Also what's the best way to update rails? I tried using

  gem update rails but it keeps me at version 1.0?

  Is the following functionality as mentioned on
http://www.ruby-forum.com/topic/24128#7157 already implemented?


 # has_many :books, :through => :authorships




Thank you for your assistance.
Frank
Go Rails!
softwareengineer 99 (Guest)
on 2006-02-07 20:09
(Received via mailing list)
Hello,
  Any ideas? on why :uniq => true is letting duplicate records go
through?
  I even tried creating a new model named Subscription for the relation
but cannot figure out how I can ensure that only one entry exists for a
member to blog relation.

  My subscriptions table contains blog_id and member_id fields. Do I
need  to add a primary key to this table even if it just holds
relations?

  I appreciate your assistance.

  Thanks
  Frank


softwareengineer 99 <removed_email_address@domain.invalid> wrote:So far I have
the following code:

  class Member < ActiveRecord::Base
       has_and_belongs_to_many :blogs, :uniq=>true
  .....
  end

  class Blog < ActiveRecord::Base
       has_and_belongs_to_many :members,  :uniq=>true
  ...
  end

  The issue is that :uniq=> true isn't working and multiple records  are
being inserted in blogs_members table when I call the following in
Member class:

    def self.create_subscription(member, blog)
      member.blogs.push_with_attributes(blog, :created_at => Time.now)
    end

  Also what's the best way to update rails? I tried using

  gem update rails but it keeps me at version 1.0?

  Is the following functionality as mentioned on
http://www.ruby-forum.com/topic/24128#7157 already implemented?


 # has_many :books, :through => :authorships




Thank you for your assistance.
Frank
Go Rails!




---------------------------------
Relax. Yahoo! Mail   virus scanning helps detect nasty
viruses!_______________________________________________
Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails
This topic is locked and can not be replied to.