Displaying 20 results from an estimated 10000 matches similar to: "has_many relationship in Gem"
2006 May 05
0
Missing documentation for find_in_collection? Trying to drill down in a 4 level has_many association fails
I''ve been reading up in ActiveRecord::Associations and playing around
with my app via the console and found some interesting methods via
the code completion of IRB, but I have no idea how to use them and
can only find one hint in the API
http://api.rubyonrails.com/classes/ActiveRecord/Associations/
ClassMethods.html
It mentions here in the has many associations that if you use the
2010 Mar 24
1
How to stub a has_many relationship in Rails 2.3.5
We have a test that has been working find until we upgraded to rails 2.3.5.
I''m not too familiar with mocks/stubs so maybe there is an easy solution.
Here is a simple example of our scenario.
Class Person < ActiveRecord::Base
has_many :aliases, :dependent => :nullify
before_destroy :mark_aliases_as_deleted
def mark_aliases_as_deleted
self.aliases.each do
2008 Jun 07
5
Can create record but can not update it => has_many through
Hi All,
I have a problem using has_many through association. I can create a product
without problem, but when i edit it, i got this NoMethodError:
undefined method `reciters='' for #<Product:0xb71a77e8>
Did i miss something to code? I provided the codes below. Please help
Thanks,
Dida
product_controller.rb
======================
def create
@product =
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
2007 Jul 29
1
Curious why this doesn't work. (has_many, belongs_to)
Two Models.
class Gm < ActiveRecord::Base
belongs_to :pool
# mode code here.
end
class Pool < ActiveRecord::Base
has_many :gms
# mode code here.
end
Testing code through the console.
>> gm_list.each{ | gm | puts " GM name: #{ gm.user_name } belongs to Pool: #{ gm.pool.pool_name } " }; nil
GM name: John belongs to Pool: RHP 07-08 Season - Career League
GM name:
2005 Dec 26
2
Dynamic order on has_many relationship?
I was wondering if it''s possible to some how control the :order given
on a has_many depending on another attribute?
Or do I need to just create multiple has_many relationships pointing
to the same table but with different orders and then select which one
I use in the controller instead?
e.g
class Category < AR::B
has_many :products, :order => //something magical?//
end
2007 May 22
3
can I use acts_as_list with a has_many :through association
I''d like to be able to use a has_many :through association and treat
the associations as a list but I''m getting this error when I try an
use an acts_as_list method:
NoMethodError: undefined method `move_to_bottom''
I''m using edge rails r6786.
Here are my domain rules:
Activities are things students can do.
Units consists of a sequenced list of
2006 Apr 03
0
with_scope used in a has_many :through model
Hi there,
I have something like the following:
class Person < AR:B
...
...
has_many :votes
has_many :chosen_answers, :through => :votes, :source => :answer, :select => ''DISTINCT answers.*'' do
def my_answers(whodunnit)
chosen_answers.with_scope(:find => { :conditions => [ "votes.created_by=?", whodunnit ] }) do
chosen_answers.find :all
2005 Nov 09
0
Sorting has_many relationships
Hi Railers!
I''m building a new website for our bar-foos-league (league for
foosball players who play in bars in Zurich, Switzerland ;-)
Being a bit of a noob when it comes to rails and web development in
general, I''ve come across a few questions. One concerns sorting of a
has_many relationship, for instance.
I''ve got a League model, which has_many TeamConfigs
2005 Dec 27
0
How do I combine :finder_sql and :conditions to perform a sub-search on a custom has_many relationship?
I''m sure there''s something right under my nose that I''m missing.
I have two tables with two parallel one-to-many relationships. I wish
to use the :finder_sql parameter to essentially ''or'' the two foreign
keys.
What isn''t working for me is performing a ''sub-search''.
Let''s say the tables are "stores" and
2006 May 16
0
Possible bug: ActiveRecord::Base::has_many fails for String arguments.
Hi
I''ve noticed ActiveRecord::Base::has_many fails for String arguments.
The following code works when all arguments to the
ActiveRecord::Base::has_many calls are Symbols:
class Country < ActiveRecord::Base
has_many :country_products, :dependent => true
has_many :products, :through => :country_products
end
ruby script/console
>> Country.find_all.first.products
2010 Jan 08
1
problem using build with has_many :through relationship
Hello all,
I''m having problems creating a new record with has_many :through
My application is quite complicated so I''ll try to explain it as easy as
I can.
I have a many to many relationship with Projects, IRBs and Reviews.
Where reviews is the joined model.
In the new project view, I have a link (add IRB). This will add an a
list of IRBs to the new project form.
I have visited
2006 Apr 04
1
Manipulating has_many :through associations
Hi,
I haven''t done any associations before, so please forgive my incorrect
use of terminology...
If I set up a has_many :through association, can I manipulate the
associated instances directly (like an Array), or do I need to
manipulate the join model?
For example, suppose I have two classes and the associated join model:
class foo
has_many :foo_bars
has_many :bars, :through
2007 May 28
2
Rails, respond_to? over anonymous module (extend has_many).
Hello List,
I''m trying to generate examples for some list-helpers I have coded
which use in my projects.
Basically, the Playlist class uses one anonymous module in has_many
that acts as helper between acts_as_list and my desired API:
class Playlist < ActiveRecord::Base
# associations go here
has_many :playlist_items, :order => :position, :dependent => :destroy
has_many
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,
2008 Feb 21
1
polymorphic has_many from ActiveRecord::Base????
I have a polymorphic thingy called fields and I need to on each and
every model, so I''d like to do the has_many from the base class, like
this...
ActiveRecord::Base.class_eval do
has_many :fields, :as => :model, :dependent => true
end
It fails with this no method error (class_of_active_record_descendant)
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.6/lib/active_record/
2012 Jun 18
0
Creating an object with a nested has_many :through relationship
I have 3 models that define members, groups and the subscriptions: Member,
Group, and GroupMember.
class Member < ActiveRecord::Base
> has_many :group_subscriptions, class_name: "GroupMember"
> has_many :groups, through: :group_subscriptions
> attr_accessible :email, :password
> end
> class Group < ActiveRecord::Base
> has_many :member_subscriptions,
2006 Jan 20
1
stack level too deep from has_many / belongs_to relationship
I have the following 3 models (2 models joined by an intermediate):
1. class Exercise < ActiveRecord::Base
2. has_many :routines, :class_name=>''RoutineExercise''
3. end
1. class Routine < ActiveRecord::Base
2. has_many :exercises,
3. :class_name=>''RoutineExercise'',
4. :order=>''position''
5. end
1. class
2006 Aug 01
2
has_many :through a belongs_to relationship
I have users who belong to a group. I also have a room that belongs to
a group. I want to use a has_many through association to link the room
and the users as such:
class Room < ActiveRecord::Base
belongs_to :group
has_many :users, :through => :group
end
The SQL generated for the search is incorrect:
SELECT users.* FROM users INNER JOIN group ON users.group_id =
groups.id WHERE
2012 Nov 03
0
ids writer fields for HABTM relationship.
Hello forum readers,
Let''s say i have two models: Person and Role (i replicated the problem
with Post & Tag as well, as i thought the problem was linked to some
application-specific rights problem, but it wasn''t).
In Person, attr_accessible role_ids is declared, so it accepts an array
of Role ids as an argument when creating / updating.
If i fire up the rails console and