similar to: HABTM - dynamic attributes

Displaying 20 results from an estimated 10000 matches similar to: "HABTM - dynamic attributes"

2006 Jan 03
0
habtm and insert_sql
Briefly, I want to create an :insert_sql attribute for a has_and_belongs_to_many relationship, and then add items to that relationship using push_with_attributes. Is that possible? Less briefly: I have a legacy postgresql database where one of the join tables has an ID column, so I had to set up the association with a custom :finder_sql attribute, as follows: class Topic <
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
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
2008 Dec 16
1
Callback when objects connect as a habtm relationship
If Product and Category models are in a habtm relationship, i.e. class Product < ActiveRecord::Base has_and_belongs_to_many :categories end class Category < ActiveRecord::Base has_and_belongs_to_many :products end I want a piece of code to be executed every time a product is connected to a category. Where do I put this code? Which callback (and on which model) will be triggered? Any
2006 May 06
3
Storing additional data on join tables with Rails
Hi there I need to store additional attributes on join table. Searching the Wiki [1] revealed two possible methods: 1) push_with_attributes, as described by Justin Palmer [2]. Unfortunately, "this method is now deprecated" [3]. Even if it wasn''t, there seem to be inherent problems with that approach, for example with updating those additional attributes, though Joshua Muheim
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/
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 Jun 16
3
Does HABTM support non "id" FKs?
Quick question. Say I have a geographical database with counties and zip codes where counties have and belong to many zip codes. zip_codes (id, zip_code) counties (id, name) When I create the association table, the Rails way says to do the following: counties_zip_codes (county_id, zip_code_id). However, given that zip_codes.zip_code is itself a candidate key, I would much prefer to do the
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 =>
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 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
2006 Jan 06
0
bug rails activerecord association join
hi, I found a bug in ActiveRecord association SQL INNER JOIN codes. in has_many, has_one, habtm and belongs_to queries the foreign key is determined from the table name of reflection and self. but that''s worng because if you use a global prefix or suffix for your tables the foreign keys will be in format of PREFIX_CLASSNAME_SUFFIX_id which is wrong, because it breaks the advantage of
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
2005 Nov 16
1
HABTM: deleting records based on attributes
Hello All, I am new to ROR, and can''t seem to get HABTM to cooperate entirely... however I might be abusing it! Before I try a different strategy I thought I''d ask here and see if I''m missing something simple. So say Projects and Companies are related. Projects can have multiple Companies, and Companies can be on multiple Projects. But, the same Company can also
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
2006 Jan 29
9
Specify options with habtm
Hi all I have the following models: class member has_and_belongs_to_many :disc_jockeys end class disc_jockey has_and_belongs_to_many :members end The relation table is called disc_jockeys_members and has the following fields: disc_jockeys_members(disc_jockey_id, member_id, status) So far, the field status can have values like valid, invalid, locked etc., but it is not regarded yet by
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 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 May 23
2
HABTM for Dummies Question
Taking time off from programming is always painful :-). I have the following Models: ==== class Tag < ActiveRecord::Base has_and_belongs_to_many :problems end class Problem < ActiveRecord::Base belongs_to :user has_and_belongs_to_many :tags end ==== And the following migrations: ==== create_table "problems" do |t| t.column "user_id", :integer
2006 Feb 12
6
habtm doesn''t save old IDs
I''m sure I''m not getting something. I have Users, and I have Groups. Each User has_and_belongs_to_many :groups and each Group has_and_belongs_to_many :users. When I add a user, I want to apply a bunch of groups (like tags) to the user (manually, without acts_as_taggable). Here''s User#create: @user = User.new(params[:user]) @user.groups =