Displaying 20 results from an estimated 5000 matches similar to: "habtm's collection_remove deprecated"
2005 Dec 30
5
HABTM with finder_sql problem (Rails bug?)
I''m building an app that needs i18n support across the entire database
(i.e. localized attributes). In order to do this I''ve created a
special HABTM join table that can be associated with _any_ other
table:
create table language_strings (
for_table varchar(255) not null,
foreign_id int not null,
language_id varchar(5) not null,
attr_name varchar(255) not null,
value text
2005 Dec 31
6
habtm recursion via destroy_without_callbacks
I am having a problem with two models that each have a HABTM
relationship to the other. For example:
CREATE TABLE people (id INT, name TEXT);
CREATE TABLE teams (id INT, name TEXT);
CREATE TABLE people_teams (person_id INT, team_id INT);
The person model has:
has_and_belongs_to_many :teams
And the team model has:
has_and_belongs_to_many :people
The trouble comes when trying to destroy
2006 May 12
2
How to declare several HABTM-relationships?
Hello,
Is it possible to have several HABTM-relationships for the same object?
Example: Imagine I have 3 objects (classroom, student, teacher) and
define the associations for the student as:
class Student < ActiveRecord::Base
has_and_belongs_to_many :classrooms
has_and_belongs_to_many :teachers
class Classroom < ActiveRecord::Base
has_and_belongs_to_many :students
class Teacher <
2006 Apr 04
1
habtm and options_from_collection_for_select [1.0.0]
I ran into a problem using options_from_collection_for_select :
ActiveRecord::AssociationTypeMismatch (Topic expected, got String):
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/
active_record/associations/association_collection.rb:128:in
`raise_on_type_mismatch''
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/
2007 Jan 03
3
Self-referential habtm with condition is broken
Here''s a simplistic model class.
class Person < ActiveRecord::Base
has_and_belongs_to_many :relatives,
:class_name => ''Person'', :join_table => ''relatives'',
:foreign_key => ''from_id'', :association_foreign_key => ''to_id''
has_and_belongs_to_many :brothers,
:class_name =>
2006 Jun 20
1
Preventing Dups in HABTM
I have a habtm that looks like:
report
has_and_belongs_to_many :subscribers
subscriber
has_and_belongs_to_many :reports
When I add a report to a subscriber, I have to run code like:
raise "already there, idiot!" unless
report.subscribers.find_by_id(subscriber_id).nil?
Is there a better way to avoid adding duplicative associations? has_many
:through seems like overkill for this
2010 Jan 20
0
need help with nested forms and habtm
Hi,
I''m currently stuck with a problem I just can''t find a clever solution
for. I checked every tutorial, issuetracker, API reference I could
find but found nothing to "enlighten" me --> I desperately need your
help :-).
My Question is: is it possible to use nested forms for habtm
associations?
--> Here some more info about what I wanted to do and what failed
2006 Jun 14
3
Prevent duplicate HABTM associations
Hi,
I am trying to restrict duplicate has_and_belongs_to_many associations.
I tried to find support for a association validation for duplicates but
couldn''t find anything.
I understand I could use :uniq=>true on the model association but this
would only prevent it from displaying duplicates, I want to stop
duplicate associations being inserted in the first place.
I have a vague
2006 Jan 06
6
HABTM problem not saving all associations
Hello all,
I have an Order object that has and belongs to many Products and has
and belongs to many Loan Types. This is so I can select multiples of
each in my order entry screen via checkbox groups.
I''m having some trouble with saving multiple HABTM associations for a
single model object; only the first HABTM association declared in the
model will save during the initial @order.save
2006 Feb 28
8
HABTM count table
Hello,
I have a question about HABTM and counting records.
I have these models
class Sort < ActiveRecord::Base
has_and_belongs_to_many :reports
end
class Report < ActiveRecord::Base
has_and_belongs_to_many :region
has_and_belongs_to_many :subjects
has_and_belongs_to_many :sorts
end
And i would like to get a count like
@sort.reports.count
The problem is get this query:
2007 Oct 05
7
Easy AR association stubbing
I''ve added a method to the mock class that makes it pretty easy to
stub associations in rails. I''ve been using it for awhile and it seems
to cut down on a lot of setup code for the controller and model specs
that use associations.
#before
@person = mock_model(Person)
posts = mock(''post_proxy'')
posts.stub!(:build).and_return(mock_model(Post, :save => true))
2006 Mar 13
3
HABTM: two habtm''s between the same two tables
Imagine I want to track people, and the clubs that they belong to.
table people with columns person_id, person_name
table clubs with columns club_id, club_name
And I have the association table:
table clubs_people with columns person_id, club_id
Now I know how to do this habtm between the two, in order to associate
people with clubs that they belong to.
However my application also needs a
2006 Aug 11
0
habtm in a standalone ruby script broken?
Hi,
i have a ruby script which uses the activerecord models of my rails
application. this is achieved with
$LOAD_PATH << ''...../availdb/app/models''
require ''rubygems''
require_gem ''activerecord''
require ''host_downtime''
require ''host_scheduled_downtime''
And in .../app/models/host_downtime.rb:
class
2006 Feb 20
0
No Magic for HABTM forms?
Hi,
I posted yesterday asking how to get form tags to reference the
associated objects in a habtm relationship. I was hoping for Rails
Magic, but it looks like Rails doesn''t have habtm magic beyond a
certain point.
Here was my solution for others who might have the problem. Also, I
hope someone shows me that there is a simpler way.
The Database Model:
class Registration <
2006 Jan 19
0
Help with nested HABTM relationship
Hi,
I am trying to perform a query with ActiveRecord that I want to put into
a Rails application later. For now I just wrote it within a plain old
Ruby script for easier testing.
I am working with an existing database so I had to map some foreign keys
myself. As you can see from the models below, the database has a
structure of
Prospectlists <=habtm=> Contacts <=habtm=> Accounts
2011 Jan 14
0
[Rail3] How to construct full-text search for habtm associations
hi all, i''m new to this group and currently using Rails 3.0.3 and meta_where
0.9.10.
i''m considering how to make a full-text searching feature to my project,
and my models, for example, should be defined like below:
class Group < ActiveRecord::Base
has_and_belongs_to_many :users
# :title (string)
end
class Comment < ActiveRecord::Base
has_and_belongs_to_many :users
2011 Apr 16
0
adding HABTM association while creating a record
Hello Experts,
I have a HABTM association as followed:
class Account < ActiveRecord::Base
has_and_belongs_to_many :user
end
class User < ActiveRecord::Base
has_and_belongs_to_many :type
has_and_belongs_to_many :account
end
class Type < ActiveRecord::Base
has_and_belongs_to_many :user
end
I have the following query;
I Have a parent user who is creating another user under its
2006 Jan 19
5
Multiple HABTM relationships with self ???
I need to have a table related to itself via a join table. Will HABTM
support this? That is:
class Recipe < ActiveRecord::Base
has_and_belongs_to_many :recipes, :join_table => "recipes_recipes"
end
More importantly -- how does RoR support MULTIPLE self-joins? I.e., to
relate the table to itself via multiple join tables.
SFAIK, HABTM won''t support multiple
2006 May 18
3
Model Madness: habtm vs through
This has me scratching my head:
a Person has many Things
a Person has many Collections
a Collection has many Things
...Things in a Collection are ordered
...Things in a Collection can be related to (created by) any User
...a collection has additional attributes, such as a name etc
I am confused about habtm in rails (especially when using
acts_as_habtm_list) vs. going the :through route.
2005 Dec 15
2
HABTM being tricky
I''ve just been bodyslammed by a problem with has_and_belongs_to_many -
as far as I can tell, if it doesn''t appear at the top of other
relationship definitions it doesn''t seem to work right. For example:
class Artist < ActiveRecord::Base
has_and_belongs_to_many :genres
has_many :albums
has_many :videos
has_many :cds
has_many :collections
end
..works fine