Displaying 20 results from an estimated 20000 matches similar to: "has_many :through, collection<<(object) and duplicates."
2009 Nov 12
0
Problem with has_many :through, :uniq => true with polymorph
Didn''t have quite enough space to describe it there...basically i''m
having a problem with the :uniq option in my tags.
I''m using acts_as_taggable_on_steroid which adds these associations to
my Resource class:
Resource
has_many :taggings, :as => :taggable, :dependent => :destroy, :include
=> :tag
has_many :tags, :through => :taggings, :uniq => true
2006 Apr 21
3
polymorphic,has_many through can not work?
Josh Susser tells in his blog that the opposite direction of polymorphic
will get into trouble together with has_many through.
This is the url:
http://blog.hasmanythrough.com/articles/2006/04/03/polymorphic-through
I do that according to Josh Susser''s procedure:
class Tagging < ActiveRecord::Base
belongs_to :tag
belongs_to :taggable, :polymorphic => true
belongs_to
2011 May 31
0
How do you test a module that extends ActiveSupport::Concern?
I have a module that extends ActiveSupport::Concern. Here is the
`included` block:
included do
after_save :save_tags
has_many :taggings, :as => :taggable
has_many :tags, :through => :taggings
end
How can I stub out these calls? I have tried a few ways, but Ruby
complains that these methods don''t exist when I try and test the
module in isolation.
Thanks!
2007 Feb 04
2
Per activerecord object callbacks (aka: should I have gone to bed hours ago?)
First of all, I should have gone to bed a long time, so please be
forgiving with regards to what will follow :)
So I''ve been working all day on a rails project that needs to go out
soon, and I thought I would try to refactor a has_many relationship to
a has_and_belongs_to_many relationship (using has_many :through).
However, I then realized that I would loose a lot of the simple beauty
2006 Apr 06
0
How to use polymorphic in a beautiful way in such a case?
class User<ActiveRecord::Base
has_many :taggings, :as=>:taggable,:dependent=>true
has_many :tags,:through=>:taggings
end
class Article<ActiveRecord::Base
has_many :taggings, :as=>:taggable,:dependent=>true
has_many :tags,:through=>:taggings
end
class Tagging<ActiveRecord::Base
belongs_to :tag
belongs_to :taggable,:polymorphic=>true
end
class Tag<ActiveRecord::Base
2007 Oct 18
0
Getting the through items from a has_many :through :uniq relationship
Getting the through items from a has_many :through :uniq relationship
In a nutshell, I have been using the has_many :through :uniq
relationship, and I want a DRY way to list the join model objects.
Currently, my objects include taxon objects, toxin objects,
data_object objects, and taxon_toxin_citation objects ("citation" is
another word for data_object). A taxon has many data objects,
2006 Aug 11
1
Avoiding adding duplicates to has_many collection?
Since there''s no ''exists?'' method for a has_many collection, is there an
easier way to avoid adding duplicates to a collection? (I assume
obj.items << item would add duplicates if repeatedly called.) Right now
I do:
category = Category.find_or_create_by_name(category_name)
directory.categories << [ category ] if
directory.categories.find(:first,
2010 Jan 27
2
has_many, through with nested models?
First the data model:
class Forum < ActiveRecord::Base
has_many :topics, :dependent => :destroy, :order => ''created_at
desc''
end
class User < ActiveRecord::Base
has_many :topics, :dependent => :destroy
has_many :comments, :dependent => :destroy
has_many :replies, :dependent => :destroy
end
class Topic < ActiveRecord::Base
belongs_to
2006 Jul 04
2
has_many working correctly only on reload!
I have this code that is using svn externals with rails EDGE working
fine for the past couple of months. A couple of days ago, this code
died. Even after deleting vendor/rails, this code doesnt work:
class Tag < ActiveRecord::Base
has_many :taggings
has_many :events, :through => :taggings
has_many :users, :through => :taggings
end
class User < ActiveRecord::Base
# Virtual
2009 Apr 12
0
rails 2.3 nested forms with has_many through checkboxes
I was wondering if anyone knew of a way to combine the new nested
forms in rails 2.3 with a has_many through relationship via
checkboxes. Basically I have a page model, a page_category model and
a category_items join table. Pages have many page categories through
category items. The category_items table is polymorphic so i can use
it for other models who need categories (maybe this is
2006 Jun 13
0
question about saving associations when using has_many :through
I''ve got a User model and a Book model. A user is required to submit
books each month to be reviewed by other users. I have the following
relationships defined:
# the join model
book_review.rb
belongs_to :user
belongs_to :book
end
book.rb
# each book is reviewed by many users. This allows us to get the BookReview
# objects associated with this book
has_many :book_reviews,
2007 Nov 22
1
has_many :through questions
I''ve created the following associations using :through:
class Person < ActiveRecord::Base
has_many :attendees, :dependent => :destroy
has_many :events, :through => :attendees, :uniq => true
end
class Event < ActiveRecord::Base
has_many :attendees, :dependent => :destroy
has_many :people, :through => :attendees, :uniq => true
2006 Feb 16
1
[PATCH] acts_as_taggable plugin
hi,
I started today to use the acts as taggable plugin and it''s working as
expected.
I added a method find_tagged_with_all since I needed to find the
elements tagged with all the items in a list while find_tagged_with
finds all the elements tagged with any of the list terms.
Attached to this mail there''s a patch which adds the
find_tagged_with_all method and which solves a
2013 May 22
3
rails 4, active record: appending to has_many :through does not create join model anymore?
hi folks.
on rails 4, can somebody confirm that pushing model instances onto a
has_many :through relation does not create the necessary join model anymore?
class Reader < AR::Base
belongs_to :post
belongs_to :person
end
class Post < AR::Base
has_many :readers
has_many :people, through: :readers
end
@post.people << Person.new
so,
2008 Apr 24
2
Dynamic finders in has_many associations
I have these 3 models.
class Ivr < ActiveRecord::Base
has_many :klusterings, :dependent => :destroy
has_many :klusters, :through => :klusterings, :uniq => true
end
class Kluster < ActiveRecord::Base
has_many :klusterings, :dependent => :destroy
has_many :ivrs, :through => :klusterings, :uniq => true
end
class Klustering < ActiveRecord::Base
belongs_to :kluster
2007 Nov 29
0
has_many_polymorphs for user owned tags
Hi all,
I''m trying to extend the tagging functionality of has_many_polymorphs to
work with user owned tags - ie, putting belongs_to :user in the Tagging
model.
So I changed the index in the generated migration, and added user_id to
the taggings table.
Then I added belongs_to :user in the Tagging model.
In the lib/tagging_extensions.rb file I added a new function:
def
2007 Mar 04
0
multiple has_many :through
hi,
simplifying I''ve this:
user -> membership -> group -> grant -> right
user has_many group through membership and group has_many right
through grant.
I can fetch the groups'' rights well, doing some console stuff like
@user.groups.each do |group| ;; group.rights.each do |right| ;; puts
right.name ;; end ;; end etc.
it would be very powerful to be able to do
2006 Dec 05
4
has_many with :uniq not working for me
Hi all,
I have a relationship (no really!)
class RiskMatrix < ActiveRecord::Base
has_many :severities, :order => :position, :uniq => true
end
class RiskFactor < ActiveRecord::Base
belongs_to :risk_matrix
validates_presence_of :descriptor, :example
validates_uniqueness_of :descriptor, :example, :scope=> :risk_matrix_id
end
class Severity < RiskFactor
2006 May 10
7
has_many :through scope on join attribute
Hi
I have a has_many :through. It''s a basic mapping of
Project
id
....
User
id
....
TeamMembers
project_id
user_id
role
What I would like to do is have different roles so I can have in the project
model
has_many :core_members, :through => :team_members, :source => :user
but I would like to limit this to only those with the "core" role in the
team members table for
2006 Mar 08
2
Need some brainstorming help: acts_as_taggable_list?
I''m trying to figure out the best way to set this data model up. I''m still
pretty new to Rails, but hopefully I could turn this into something useful
to others as well. Here are the basics:
User has_many items
items are taggable (items habtm taggings, tags habtm taggings)
I also want users to be able to order their tagged items. So if I''ve
tagged 5 items as