Displaying 20 results from an estimated 9000 matches similar to: "has_many :through associated object ids assignment error"
2006 Jan 20
11
HABTM relations
Hi,
I have 3 tables with HABTM relation.
USERS -> QUOTE_TO_USER <- QUOTES
Table QUOTE_TO_USER has 3 attributes: quote_id, user_id, component.
I have a form where I can tie multiple users to QUOTE. This is easy one,
thru "user_ids" (@quote[:user_ids] = @params[:quote][:user_ids]).
In this form I have all users and I just check those I want to tie to
this quote, however
2006 Dec 25
2
how to insert data using has_and_belongs_to_many
I''am newbie in RoR, so my question might look stupid, but I stuck in one
thing.
I''ve created 3 tables:
users{
id,
user
}
books
{
id,
book
}
books_users{
book_id,
user_id}
Model
class Book< ActiveRecord::Base
has_and_belongs_to_many:users
I can''t figure out how to insert data to the books_users table.
For example users post info about new book and information
2006 Jul 04
8
writing to many_to_many table
I have three tables. users, posts, users_posts. This last one is to
mark a post as read.
How do I write to the users_post table?
Here''s what I have:
In model ''User_Post''
belongs_to :post
belongs_to :user
In post/view/show:
<%= link_to "Mark As Read", :controller => ''post'', :action =>
''post_read'',
:user =>
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 Sep 28
5
Eager loading using find_by_sql
Here''s the problem I have the following models
User - is a person
Team - is a team
Wherenote - snipet of info about a user''s whereabouts on a certain day
Team has_and_belongs_to_many :users
User has_and_belongs_to_many :teams
has_many :wherenotes
Wherenote belongs_to :user
each Wherenote has a note_date
On one page I want to pull back all the Users from a particular Team
2006 Apr 26
2
Multiple Select example?
I''ve been trying to sort out a multiple select dropdown but haven''t
found any good examples - anyone know of any or perhaps could make a
suggestion [see below]
Model:
1. Task AR has_many users
2. User AR belongs_to task
login/password attributes
Controller:
View:
<%= collection_select("task", "users" , @users, "id", "login", {},
2006 Jul 04
1
Has_many :through with checkboxes?
Just when I started getting the hang of has_and_belongs_to_many
relationships, I realize that I should probably convert several of my
app''s joins to has_many :through type relationships.
One example, pairing users with categories via subscriptions, where
each user can be the "owner" of a category, has given me particular
trouble when I try to update a user''s
2006 Jul 26
8
team captain - habtm w/has_one...
the below...
class User < ActiveRecord::Base
has_and_belongs_to_many :teams
class Team < ActiveRecord::Base
has_and_belongs_to_many :users
has_one :captain, :class_name => ''User''
produces the error...
Mysql::Error: Unknown column ''users.team_id'' in ''where clause'': SELECT *
FROM users WHERE (users.team_id = 1) LIMIT 1
i
2006 Jan 06
1
has_many with :finder_sql question
hi all,
I have a Class, Client, which has_many projects (Project class). the
projects depend on a session_id variable, however. So the question
is, how can I do the following:
has_many :projects,
:finder_sql => "SELECT p.* FROM projects p INNER JOIN
projects_users pu ON pu.project_id = p.id WHERE pu.user_id =
#{session[:user_id]}"
The problem is that I need to filter a
2008 Apr 18
3
has_many and belongs_to with non-primary foreign keys
Hi,
I''m having a bit of trouble with my first Rails app.
----
I have two tables:
create_table :items do |t|
t.column :created_at, :timestamp
t.column :user_id, :int
t.column :text, :text
end
create_table :users do |t|
t.column :user_id, :int
t.column :name, :string
end
----
I''m trying to use the "user_id" field to link both tables, with each
user
2009 Jan 04
3
Table associated problem using belongs_to
I have two tables:
Table [packages]
id name user_name
-------------------
1 PK1 Ray
-------------------
Table [users]
id name full_name
-------------------
2 Ray Ray Sun
-------------------
My purpose is to find the full name when I find packages. So I modify
Model Package to:
class Package < ActiveRecord::Base
belongs_to :user,
:class_name => "User",
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 Apr 03
1
has_many :trough with 2x the same table
I have a site where Users can become Friends with other Users. I used to do this with a habtm, but of course I want to stay up-to-date and convert this to a has_many :trough. Unfortunately I can''t get it to work.. the documentation on this feature is a bit sparse at the moment.
This is my old habtm:
has_and_belongs_to_many :friends, :join_table => ''user_friends'',
2006 Jun 26
4
has_many :through
first, the models:
class Listing < ActiveRecord::Base
has_many :keyword_links
has_many :keywords, :through => :keyword_links, :conditions => "active =
1"
end
class Keyword < ActiveRecord::Base
has_many :keyword_links
has_many :listings, :through => :keyword_links, :conditions => "active =
1"
end
class KeywordLink < ActiveRecord::Base
belongs_to
2010 Aug 18
6
Once I added this HABTM, one of my 'through' relationships, on a non-habtm model, seems to have broke?
I''m a rails newb and have been Googling about this, but I''m still stumped.
Not showing everything here, but basically it should be a pretty common
setup so I''m sure others know what I''m doing wrong.
- A meter can belong to many meter_groups
- A meter_group can have many meters.
- A user can ''subscribe'' to viewing a meter_group (Subscription)
2007 Apr 04
4
Order a find using a has_many association
I''m trying to order a find through a has_many association. I have a
model called SalesOrder. Each sales order has things like amount,
description, etc. I use the following to get the Sales Orders:
@sales_orders = SalesOrder.find(:all)
And I display them with:
<td><%= link_to sales_order.id.to_s, :action => ''show'', :id =>
sales_order.id
2007 May 04
1
habtm and also has_many of the same things
Hi,
our app is a situation where users can upload files and also mark files
uploaded by other users as their favorites. So for the favorites we are
using a simple many-to-many with a tie table.
So in attempting that it looks like
class User < ActiveRecord::Base
has_and_belongs_to_many :media_file
has_many :media_file
end
class MediaFile < ActiveRecord::Base
2006 Mar 19
1
some strange behavior for has_many with STI
Hi all,
I''m having some trouble with a has_many association on a table using
the single table inheritance model that I''m hoping someone can help me
with. The schema for the table is:
CREATE TABLE `comments` (
`id` int(11) NOT NULL auto_increment,
`user_id` int(11) default NULL,
`type` varchar(20) NOT NULL default '''',
`type_id` int(11) NOT NULL default
2006 Apr 16
6
still learning maintaining data with join tables
Class Role
has_and_belongs_to_many :users
Class User
has_and_belongs_to_many :roles
Class RolesUsers
has_and_belongs_to_many :roles
has_and_belongs_to_many :users
According to the logs...I''m good through here
@roles_users = RolesUsers.find(:all,
:conditions => ["user_id = ?", params[:users_id]] )
the next section of controller code is a problem...
2006 Feb 27
4
2 belongs_to to the same parent table
Hello!
I have 2 table: users and buddies
User: id, name, ...
Buddy: id, user_id, user_buddy_id, ...
So if you have 2 users 1,jack and 2,fred and fred is a buddy of jack,
there is a Buddy object: id=1, user_id=1, user_buddy_id=2
I can declare only one belongs_to in Buddy and one has_many in User. And
there is conflict if I had the second one (the first one is discarded)
class User
has_many