Displaying 20 results from an estimated 10000 matches similar to: "How to override append method for related attribute?"
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 Jul 10
18
Deleting join association of has_many :through
I''m trying to use has_many :through, since my join model deserves being
more than just an intersection table.
But when I try to break the association, the break only seems
"temporary":
Let''s say my two tables are Users and Colors, and the join model is
Favorites.
user = Users.find(1)
user.colors.length
>> 2
c = user.colors.first
>> #<Color:....>
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 Aug 11
6
Newbie Question -- Override String functionality
Hello,
I would like to add functionality to the String class....where do I do
this?
Do I create a new model (if so, what do I call it?) and put something
like:
class String
def my_new_string_method
blah blah
end
end
Thanks for any pointers.
--
Posted via http://www.ruby-forum.com/.
2006 Jul 04
2
has_many working correctly only on reload!
I have this code that is using svn externals with rails EDGE working
fine for the past couple of months. A couple of days ago, this code
died. Even after deleting vendor/rails, this code doesnt work:
class Tag < ActiveRecord::Base
has_many :taggings
has_many :events, :through => :taggings
has_many :users, :through => :taggings
end
class User < ActiveRecord::Base
# Virtual
2006 May 19
7
How can I set up relations for these models?
Hello!
I have a legacy DB and want to use ActiveRecord for it.
However, I can''t set up a relation correctly.
Here''s table spec:
[products]
id
name
price
[subproducts]
product_id
subproduct_id
Some example data:
[products]
1, "Computer", 500.00
2, "Monitor", 200.00
3, "Printer", 100.00
4, "System", 700.00
5, "System2",
2006 Jul 10
7
What is has_many :through really buying you over HABTM?
So having just learned how to do has_many :through as opposed to HABTM,
and then, being concerned that I wouldn''t get it to work, I started
thinking about these two approaches.
It seems to me that the _only_ problem that the HM:T (has_many :through)
approach solves that HABTM doesn''t is the issue of the potential
collision of id columns between your join table and one of
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 May 16
4
Problems with multiple ''id'' columns in a join_table
I have a problem declaring a relationship through a join_table ; the SQL
generated by ActiveRecord is correct, but there are two columns called
''id'', and the final object gets the ''wrong'' column ...
Here''s a more detailed description of the data, code, and problem :-
There''s a People table, with id, name, and a few things.
Also a
2006 Jul 05
7
HABTM join table has an "ID" column - is this an issue?
All,
I''m building model objects for existing tables that I cannot modify.
In AWDWR, Dave says "Note that our join table has no id column...The
second reason for not including an id column in the join table is that
AR automatically includes all columns from the join tables when
accessing rows using it. If the join table included a column called id,
its id would overwrite the id
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 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/.
2006 Mar 29
4
:through alternate
I''d like to use :through to create a web of associations like:
class Thing < ActiveRecord::Base
has_many :child_things, :through => :thing_thing
has_many :parent_things, :through => :thing_thing, :some_other_option?
end
class ThingThing < ActiveRecord::Base
belongs_to :thing
belongs_to :child_thing, :class_name => ''Thing'', :foreign_key =>
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
2006 Jun 06
6
Linking two tables using a lookup table
Hi,
How do I associate two different tables which have a lookup id (table)
as common.
I tried the has_many :table2, :through => look_up_table in my table1
model.
Any hints?
Thanks, Hari
--
Posted via http://www.ruby-forum.com/.
2006 Apr 24
9
Confusion with expressing many to many relationship
Hi folks, I am in the process of converting an existing non-rails
application to rails, and am not sure what the best approach would be
for specifying the relationship between the two sets of data.
I''ll describe the existing table structures first.
Table 1: Urls
Each url has a unique id and two lists of Phrases, these are currently
setup as varchars with "," delimitation -
2006 Aug 12
7
Collection assignment to a has_many :through
I''m working on a simple photo gallery in rails, it seems to be a good
project for a newbie.
I have photos and categories, many-to-many association. It worked well
with HABTM. Then I decided that it would be good to be able to change
order of the photos so that thumbnail pages would look less chaotic.
So I created a Layout model which is a join model (or whatever it is
called) that
2006 May 27
7
How should I select rows from a join-model based on more than one association?
A concrete example:
We''re building a system to organize the information about workshops
being held in various conventions. A convention has more than one
workshop, and each workshop can be held in more than one convention.
Also each workshop has a host, who is specific to a workshop being
held in a specific convention.
For example, Matz may host an "Introduction to Ruby"
2006 Jun 04
6
Activerecord relations.
I''ve got two tables set up - Things and Users where Users have many
things and Things belongs to Users.
They''re connected by Things.user_id => User.id and Things.updated_by_id
=> User.id both in the Things model using Belongs_to and custom foreign
key for one of them.
Problem is when I''ve got the updated_by_id belongs_to I can''t add Things
using
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/.