Displaying 20 results from an estimated 3000 matches similar to: "Using Migrations to convert join table to join model"
2007 Dec 28
1
validation of acts_as_list in the model of the base class?
Lets say I have 3 models, user, user_group and user_group_nodes. A
normal user has one user_group_id as a foreign key and a special user
has multiple user_groups which are defined in the user_group_nodes.
The user_group_nodes is a "acts_as_list" for user and contains a list
of group_ids.
When I build a form to get user input and I want to save it, is there
a way to validate the
2006 Aug 02
2
mangle ActiveRecord
Dear Gurus on Rails!
How do I change the behaviour of one method in
ActiveRecord::ConnectionAdapters::SchemaStatements ?
Full story:
I''d like to mangle
ActiveRecord::ConnectionAdapters::SchemaStatements
so when it creates a new sql table, it also (optionally) creates my
created_at, deleted, key_id, session_id etc columns that I use on basically
all tables.
It would not be DRY to repeat
2010 Mar 07
6
some love for migrations
I have a semi-grand plan for some changes to migrations. Mostly this
is motivated by the upcoming 3.0 release and wanting to get migrations
in engines working.
1. Don''t skip migrations with version numbers lower than "current".
I only recently tripped over this, but apparently it''s been this way
since 2.1 when we got timestamps masquerading as large/sparse
2006 Jun 05
5
adding habtm through migrations
Hello,
I''m stuck, I''ve got a model Product and would like to add a new model
called Category. Furthermore, I want to set up a many2many
relationship between the mentioned models. the problem is that I do
not know how to set the primary key in the categories_products table.
this is what I''ve got in my migration file:
create_table :categories do |t|
t.column :name,
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 Apr 06
1
Primary keys and migrations
I have a join table I''m creating with a migration as follows:
create_table :read_global_messages, :id=>false do |t|
t.column :user_id, :integer
t.column :message_id, :integer
end
So far so good, however I want the primary key to be user_id and
message_id. How do I do this?
I tried the following, but that doesn''t work:
add_index
2006 May 14
2
object class with STI and Polymorphic Assoc''s.
Hi, lets say I have a a table, "Linkings" that I am using for
polymorphic associations. One of the associations is to the "person"
table, and there are several other associations.
"Person" has 2 types, "slacker" and "suckup".
It is modelled as such:
class Linking < ActiveRecord::Base
belongs_to :person
belongs_to :linkable, :polymorphic
2006 Aug 03
12
More than one has_many :through association between the same 2 models
I wonder if you can have more than one has_many :through association between
2 models.
For example...
I have a model Teacher and a model Class
Now, 1 Teacher works in many Classes, right?. So I need a join model like
class Work < ActiveRecord::Base
belongs_to :teacher
belongs_to :class
end
But I also would like to know if a teacher CAN teach a class before I
2006 Jul 28
11
Forum
Im making forum and i have problem with paths.
Here is code:
http://pastie.caboo.se/6389
With this code, it works. But its a bit weird to use so many paths
function. For every path i need to make new function. So can you suggest
me something.
Tables are like here:
http://wiki.rubyonrails.com/rails/pages/ForumExample
--
Posted via http://www.ruby-forum.com/.
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 May 28
7
Join table not being populated
Hello,
I have the usual Categories and Products table scenario, mediated by a
Categories_Products join table. When I create a new Product and into a
given Category, I notice that my join table is not being populated.
Shouldn''t the join Categories_Products table be populated?
Thanks,
gk
--
Posted via http://www.ruby-forum.com/.
2005 Dec 05
0
bug in bubbleshare's Active Record extensions?
I''m using add_foreign_key_constraint and remove_foreign_key_constraint
from Bubbleshare''s Active Records Extension plugin now to manage the
foreign key relationships I describe in my other recent posting. The
constraints get added within migrations, but I''m running into two
problems (Rails 0.14.3, PostgreSQL db):
1. Dumping the schema doesn''t dump the
2007 Sep 20
1
Relationship Proxies?
I''m trying to understand these results in irb, which implies that
there''s some kind of proxy at play:
>> aaron = User.find_by_login ''aaron''
=> #<User:0xb7109cdc
@attributes={"salt"=>"7e3041ebc2fc05a40c60028e2c4901a81035d3cd",
"updated_at"=>nil, "contact_info_id"=>nil,
2006 May 21
3
has_many :through with a polymorphic join
Hi,
Four tables: users, user_counties, uk_counties and us_counties.
Each user has many counties, and each county has many users, so I
decided to make user_counties a polymorph, so it can have counties
from different countries (each country requires a completely different
set of tables with a completely different set of properties, that''s
why there''s one table for uk_counties and
2007 Dec 12
7
Release Retrospective
First off, congrats to everyone for getting Rails 2 released. A lot
of work went into the release, and it''s good to see us reach this
milestone. And now that the release dust has settled, I think it
might be useful for us to have a retrospective and evaluate how the
release went.
I think the Ruby on Rails project has improved a lot this year, and
this is another opportunity
2006 May 10
7
has_many :through scope on join attribute
Hi
I have a has_many :through. It''s a basic mapping of
Project
id
....
User
id
....
TeamMembers
project_id
user_id
role
What I would like to do is have different roles so I can have in the project
model
has_many :core_members, :through => :team_members, :source => :user
but I would like to limit this to only those with the "core" role in the
team members table for
2006 Apr 05
5
Updating attributes in HABTM association
Hi,
I am trying to find a way tp update attributes in a habtm association. I
am trying to use the code from ticket #2462, but as my
association_class_primary_key_name seems to be empty the generated sql
code is corrupt. I hope thats not a problem of my model that this
variable is empty.
What would you recommend to update those attributes (rails 1.1)
THANKS!!!
--
Posted via
2006 Apr 20
3
has_many :through with has_many/has_many join models
It seems that using a join model that joins with two has_many''s will
fail to generate proper SQL
class StudentSemesterRecord < ActiveRecord::Base
belongs_to :semester
has_many :discipline_records, :through => :semester
end
class Semester < ActiveRecord::Base
has_many :student_semester_records
has_many :discipline_records
end
class DisciplineRecord <
2006 Jul 10
10
has_many :through and foreign key parameters
I just took my HABTM and turned it into a :through since my join table
has another "non-joiny" attribute.
I went from this:
has_many_and_belongs_to :jobs, :join_table => ''tablename'',
:foreign_key => ''x'',
:association_foreign_key => ''y''
to this:
has_many :jobs, :through =>
2006 Mar 14
5
Column aliasing in ActiveRecord?
Anybody know of a way to alias a column in ActiveRecord such that you
could reference it via a different symbol in your view for view
purposes?
Like my column is named X but I want to display it as Y and maybe I have
an accessor named Y set up on the model so that when I "call" Y from the
view (and controller?) I''m actually manipulating the column X?
Hope that makes sense.