Displaying 20 results from an estimated 10000 matches similar to: "Rails 4 deprecation of in-place edit methods for collection associations"
2009 Feb 04
2
delete_if does not work on associations
I tried to user delete_if on an association:
class Group < ActiveRecord::Base
has_many :memberships, :dependent => :destroy
has_many :users, :through => :memberships
...
end
This is the controller method, trying to use delete_if. Although some
elements are removed (s2 < s1), the save method does not update the
association.
def intersect_or_remove_group
other_group =
2008 Aug 20
1
Problems with namespaces
Hi, I'm trying to create Shared folder with subfolders "SPAM" and
"NOT_Spam". Configuration: namespace public { separator = / prefix
= Shared/ location =
maildir:/vmail/%Ld/Shared:INDEX=/vmail/%Ld/%Ln/Shared hidden = no }
Result I get (is exactly what I want): Inbox Drafts Sent Trash Shared
--NOT_Spam --SPAM I can select SPAM and NOT_Spam, delete messages etc,
but
2013 Dec 17
1
Tire: Problem with including associations while doing a multi-model search
I am using elasticsearch for querying in my application. Lets say there
are 2 models
Class Topic
has_many :posts
and
Class Article
has_many :comments
I want to do a combined search on both these models and my query looks
like:
Tire.search [Article, Topic], {:load => {:include => [:posts,
:comments]}} do |search|
...
end
This is where I encounter a problem. I get the
Association
2006 Sep 25
2
@article.article_groups.delete_if... Dosn't work!
If I try:
@article.article_groups.delete_if {|x|
x.group_id == x.group_id
}
It does nothing.
If I try:
articletmp.article_groups.each{ |x|
@article.article_groups.delete(y)
}
It deletes some of the groups.
@article.article_groups.clear
works.
Why dosn''t the to first examples work as expected??
Do I have to put groups I don''t want to
2006 Aug 08
12
delete_if doesn''t work for has_and_belongs_to_many
I''m using Rails-1.1.4 with Ruby-1.8.4
So let''s say I have 2 model classes:
class Item
has_and_belongs_to_many :things
end
class Thing
has_and_belongs_to_many :items
end
i = Item.new
i.things << Thing.new( :value => "Something").save
i.things << Thing.new( :value => "Something Else" ).save
i.save
Fine, now I have two records in the
2006 May 23
6
How to list all models of an application?!?
How can I get a list of all model classes in the domain of a Rails
application (all models, both in "app/models" and in
components/somedir/model.rb)?
Thanx in advance for your precious help!
Edoardo "Dado" Marcora
2013 Jul 11
1
Do I Edit the Migration Too to Show the Belongs To
Hi Everyone,
Do I edit the corresponding migration also to show the belongs_to (and the
has_many)? I have a many to many relationship where I am using the
"has_many :through" association. When I place in the individual classes the
''has_many :through'' and the ''belongs_to'' associations, do I also edit the
corresponding migrations to reflect those
2006 May 26
4
shouldn''t this work? - session[:array_of_objects].delete_if {|x| x.id == params[:id]}
I am saving an array of active record objects (college courses) in the
session as session[:course_list]. This is the cart for a registration
controller.
If a student chooses to delete the course from the list I get the :id
as params[:id].
However if I do
session[:course_list].delete_if {|x| x.id ==params[:id]}
does not work.
session[:course_list].delete_at(idx)
works. Ocourse to do this I have
2013 Jul 21
4
how to use activemodel collection.build for a has_many :through association
Hi all,
In my controller I am doing the following to populate a nested form for a
has_many through association:
def new
@specification = Specification.new
Component.find_each.each do |component|
@specification.component_specifications.build(:component_id =>
component.id)
end
The idea being whenever someone creates or edits a form, it will be
populated with all
2006 Mar 18
4
Accessing overridden method
I have two model classes:
class Item < ActiveRecord::Base
belongs_to :channel, :counter_cache => true
validates_presence_of :channel
end
class Channel < ActiveRecord::Base
has_many :items, :dependent => true
end
In the Channel controller I have variable channel.items, an Array of
Items. I would like to use the Array find method. However,
channel.items.find() is a Rails
2008 Apr 11
2
Validating an ActiveRecord object and its has_many :through associations
Considering an object with several has_many :through => associations,
what is the ''best'' way to handle validations?
As an example:
class Student < ActiveRecord::Base
# some attrbutes like
# :name
# :grade
# relationships
has_many :students_assignment, :dependent => :destroy
has_many :assignments, :through => :students_assignment
has_many
2006 Apr 20
4
Question about Associations
Hi all. Got a stupid-simple question about associations. I have two
models - school and course. There are a fixed number of schools (set
up in the migration). Each course is assigned a school and a school
will be associated with multiple courses...
How do I set up the associations? Do (can) I have School :has_one
:course and Course :has_many :schools?
Does the schools table then get a course_id
2006 Aug 16
1
Naming rights_roles join model using has_many :through and polymorphic associations
Hi.
I have a couple of best practices questions regarding polymorphic
associations, naming join tables and user permissions.
Currently I have implemented the user authentication model from the
rails recipes book. Basically it goes something like this:
MODEL CLASSES:
class User < ActiveRecord::Base
has_and_belongs_to_many :roles
end
class Role < ActiveRecord::Base
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
2006 Apr 09
4
Inheritance via Though Associations?
I posted something about this a week ago wihtout response, but have made some
progress since. However, I''m still not getting exactly what I want.
OK, three core tables:
create_table :reference_items do |t|
t.column :title, :string, :limit => 255
t.column :year, :integer, :limit => 4
t.column :type, :string
t.column
2006 May 11
6
ActiveRecord associations
Can someone clarify this for me? Suppose I have two tables like:
class Company < ActiveRecord::Base
belongs_to :category
end
class Category < ActiveRecord::Base
has_many :companies
end
I understand that the belongs_to causes related companies to be read
from the db when I ask for a category. I suspect SQL something like
select * from categories, companies
where category.id
2009 Aug 06
2
duplicate model object with associations ?
class Patient < AR::Base
has_many :aaas
has_many :bbbs ,:through=>:aaas
end
class Aaa < AR::Base
has_many :bbbs
end
-------
i want like this
@patient=Patient.find(id)
@new_patient=@patient.duplicate
now the
@new_patient should have their own copy of patient,aaas,bbbs (new
records in corresponding tables)
there is one options is that
we can create seperate object for each
2007 Oct 23
1
storeconfig DEPRECATION WARNING
Hi,
here is a warningmessage i got while i am testing my new puppet
installation with .23.2 and storedconfig and reports and all the bell
and whistle :)
DEPRECATION WARNING: Calling .create on a has_many association without
saving its owner will not work in rails 2.0, you probably want .build
instead See http://www.rubyonrails.org/deprecation for details. (called
from create at
2007 Jul 04
3
Testing Rails Associations
Hi,
I''m very new to rspec, so if this is not the right forum please let me know.
I''m starting to spec my models first in an existing rails app, porting from
a mix of Test::Unit, and simply_bdd amongst others.
I''m at the point where I want to test that certain associations are
present. What I''m not sure of is should I test the association or the
method and
2006 Nov 26
5
associations help?
I have Users who can "own" Projects. There is only one owner. Users in
general can be authorized to view certain projects. Here is my initial stab
at this:
class User < ActiveRecord::Base
has_many :projects # ownership
has_many :project_viewers, :dependent => :destroy
has_many :projects, :through => :project_viewers, :uniq => true
...
end
class