Displaying 20 results from an estimated 600 matches similar to: "Updating Attributes in a HABTM Join Table"
2006 Apr 29
5
HABTM - how to insert join row when associated rows exist
I have successfully used HABTM to create a many-to-one-to-many set of
rows in one step. Now, if two objects I want to associate already exist,
how do I create the join row? The Agile book mentions the
''push_with_attributes'' method. The text says this method is useful for
adding additional attributes to the join row (in the example a ''read_at''
timestamp). I
2006 May 05
4
STI and HABTM
Hey gang,
How does STI work with HABTM?
For instance...let''s say I have the following models
-----
Category < ActiveRecord::Base
Item < ActiveRecord::Base
Product < Item
Deal < Item
-----
Each product or deal can have categories. Would I then setup Item with
has_and_belongs_to_many :categories, then create a table categories_items
??? Is there a better way to do it?
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 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.
2006 Mar 01
6
How to retrieve attributes from HABTM?
We have tables Users and Communities linked by has_an_belongs_to_many.
The join table Communities_Users has additional fields [ is_active,
is_blocked, join_date] etc. These are populated using
@user.push_with_attributes(:is_active => true,...).
Later on how do we update or retrieve the attributes in the link table
for a given user or a community with doing it explicitly using SQL?
Thanks,
2006 Feb 07
1
habtm :uniq causing duplicate inserts? How to update Rails?
Hello *Gem* experts,
Sorry for asking multiple questions in one post but they are both related to one problem.
So far I have the following code:
class Member < ActiveRecord::Base
has_and_belongs_to_many :blogs, :uniq=>true
.....
end
class Blog < ActiveRecord::Base
has_and_belongs_to_many :members, :uniq=>true
...
end
The issue is that
2006 Apr 23
0
Severe STI, HABTM with Attributes and 1.1
All,
I had been working on a project that was using STI to a very high
degree. It also was using a HABTM table that had a couple extra
attributes. It seems that with 1.1 push_with_attributes is deprecated
and I am having a bit of trouble moving things to using has_many
:through
The original schema I had worked like this :
create_table "nodes" do |t|
t.column "title",
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
2006 Jan 10
1
sql server freetds/odbc question
I''m having an error from Linux via freeTDS/ODBC to SQL Server with
cod that runs fine against SQLite and MySQL. Here''s the code:
def find_recipes_for_workorder_by_id
@recipe_pages, @recipes = paginate_with_sort :recipes, :per_page
=> 10, \
:conditions => ["recipe.workorder_id = ?", params
[:workorder]]
render :template =>
2005 Jun 13
1
Question on Eager Associations
Hi - I am trying to use eager associations to cut down on database queries.
I have a feeds table, an items table, a categories table, and a
categories_items table.
feeds have items, and items have many categories (and categories can
be assigned to many items), thus the categories_items table which is a
many-many join table.
I do
@feed = Feed.find(1)
which works fine, but now I want to use
2006 Jan 04
0
Re: DB Modelling the Rails way - solution by Chris Hall
Hi Chris,
Yesterday you kindly submitted an answer to my question on modelling
many to many relationships. I''ve briefly tried the proposed solution but
so far with no luck. Before I get too involved - I''d like to know if
mapping three way :join_tables is "legal" in a Rails sense. I only ask
since you put (untested) in your mail and I can''t find any docs on
2006 Jan 10
1
sql server & linux: left join problem
I''ve got a left join problem of some sort connecting from linux
FreeTDS/ODBC to SQL Server. It''s similar to the false post I had
earlier, but this is a real problem. Here''s my code:
def find_recipes_for_workorder
@recipe_pages, @recipes = paginate_with_sort :recipes, :per_page
=> 10, \
:joins => ''left join workorder on
2006 Jan 07
4
To Chris Hall - Re: DB Modelling the Rails way - Opinions??
Chris,
Finally got time to fully play with your suggestions. Had to re-code a
bit of stuff but the concept works - just like a bought one :~). Many
thanks for the solution,
Kind Regards,
Eric.
For those curious - here''s what it was about;
On Monday 02 January 2006 02:10, Eric Sloane tried to type something like:
> Hi,
> I''m trying to figure the most efficient way to
2006 Apr 27
1
issue with deprecatiing push_with_attributes
I''ve been listening to the discussions regarding the plans to eliminate
push_with_attributes. While I think it''s good practice to make join models
if you''re developing a new system, I can''t help but think t hat
push_with_attributes should be left around to deal with legacy databases.
I might want to wrap my application around a database I don''t
2006 Mar 15
1
push_with_attributes not inserting default values
I have a join table A_B with columns[a_id, b_id, c_data default 1,
d_data default 1].
If I do:
@aobj.bobjs.push_with_attributes(@bobj,{:c_data => 0})
I find that the row inserted, has d_data set to 0 and not the default
value specified in the database, which is 1. So I am having to
explicitly set it using :
@aobj.bobjs.push_with_attributes(@bobj,{:c_data => 0, :d_data => 1}).
Is this
2005 Mar 13
1
Semantics of push_with_attributes
In trying to add timestamp support to habtm, I''ve stumped on a question
which I hope you all help me solve.
And that is, when adding a record twice to the list of associations with
push with attributes, should the following test succeed or not?
def test_pushing_twice
dev = Devel.new("name"=>"victor")
p =
2006 Jul 31
1
Use of push_with_attributes
Hi,
I have a model class called Page and a corresponding pages table in the
db.
Is there a way to do Page.new without actually creating a corresponding
record in the table? I want to set some values in it and then pass it to
the add_content_component() method in the class below which calls
push_with_attributes() which will actually create the record in the db?
class Page <
2006 Apr 14
2
Nested AJAX remote_form in form?
I''d like to achieve something that is better described by the following
code:
<%= start_form_tag :action => ''create'' %>
<%= text_area ''place'', ''description'', :cols => 100, :rows => 4 %>
<div id="categories">
<%= form_remote_tag :update => ''categories'',
2006 Jun 05
7
Is HABTM Dying?
For a while, I''ve been getting that HMT is replacing HABTM. It appears that
HMT can do all of what HABTM can do and more. The question is: Should I stop
using HABTM? Let''s take a simple case:
A case has many categories
For a given category, there are certain valid statuses
Category
has_and_belongs_to_many :statuses
Status
has_and_belongs_to_many :categories
Question:
Is
2006 Jan 02
1
ActiveRecord, << or push_with_attributes: update if exists?
In the Agile Rails book, on page 232 (PDF, 4th edition) there is an
example of (within ActiveRecord) marking an article as read by a user at
the present time. Short example code (from the book) here:
class User < ActiveRecord::Base
has_and_belongs_to_many :articles
def read_article(article)
articles.push_with_attributes(article, :read_at => Time.now)
end
# ...
end