Displaying 20 results from an estimated 30 matches for "push_with_attribut".
Did you mean:
push_with_attributes
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 contro...
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 a bug in Rails 1.0?
Also,...
2005 Mar 13
1
Semantics of push_with_attributes
...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 = Project.new("name"=>"whatever")
dev.projects.push_with_attributes(p, :joined_on => Date.today)
dev.projects.push_with_attributes(p, :joined_on => Date.today)
assert_equal(1,dev.projects.size)
end
That is, should the record be added twice, or else updated with new
info? And for that matter, should the normal push (or <<) method add
twice if...
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 < ActiveRecord::Base
has_and_belongs_to_many :contentcomponents
...
def add_content_component(content_component)
pos = Integer(contentcomponents.size) + 1
contentcomponents.push_with_attributes(content_component, :po...
2006 Jan 02
1
ActiveRecord, << or push_with_attributes: update if exists?
...ook, 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
However, it seems this piece of code would only work the first time you
read a specific article. It appears to always create a new join table
post, and not to just update if there is an existing post. How would one
best solve this?
--...
2006 Jan 02
2
ActiveRecord:
...ook, 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
However, it seems this piece of code would only work the first time you
read a specific article. It appears to always create a new join table
post, and not to just update if there is an existing post. How would one
best solve this?
--...
2006 Jan 04
0
Re: DB Modelling the Rails way - solution by Chris Hall
...quot; (id = 2) role to Project 10
>
> john = Person.find_by_name("John")
> manager = Role.find_by_name("Manager")
> project.find(10)
>
> with this information, you could do it several different
> ways...depending on the situation
>
> project.people.push_with_attributes(john, :role_id => manager.id
> <http://manager.id>)
> project.roles.push_with_attributes(manager, :person_id => john.id
> <http://john.id>)
> john.projects.push_with_attributes(project, :role_id => manager.id
> <http://manager.id>)
> john.roles.push...
2006 Jan 02
5
DB Modelling the Rails way - Opinions??
Hi,
I''m trying to figure the most efficient way to model the following. I
can think of at least two ways to relate the tables but from a
client/server perspective! I''m wondering how to best (and
elegantly)relate them from an AR perspective.
A project has many people,
A person can work on many projects at any time,
A project has many roles,
A role is performed by a person,
A
2006 Jan 07
4
To Chris Hall - Re: DB Modelling the Rails way - Opinions??
...say you want to add John as a "manager" (id = 2) role to Project 10
john = Person.find_by_name("John")
manager = Role.find_by_name("Manager")
project.find(10)
with this information, you could do it several different
ways...depending on the situation
project.people.push_with_attributes(john, :role_id => manager.id)
project.roles.push_with_attributes(manager, :person_id => john.id)
john.projects.push_with_attributes(project, :role_id => manager.id)
john.roles.push_with_attributes(manager, :project_id => project.id)
role.projects.push_with_attributes(project, :person_...
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 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 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 only require a simple two-key join row - is
''push_with_attributes'' the way to go?
-Lindsay
--
Posted via http:...
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,
Yash
--
Posted via http://www.ruby-forum.com/.
2005 Dec 15
2
efficient INSERTS
Hi,
I''ve got the following models:
Company
Package
with a habtm relationship.
In my controller, I have a ''dispatch'' action which does the following
@companies.each do |company|
@packages.each do |package|
company.packages.push_with_attributes(package, :sent_on => Time.now)
end
end
my table ''companies_packages'' therefore lists which company was sent which
package at what time.
If I''m sending 20 packages to 20 companies though, I generate 400 INSERT
statements. Is there a rails way of doing this more ef...
2006 Jan 21
7
n-way joins
Hi,
I''m somewhat of a Rails newbie and am trying to understand how to
formulate n-way (3 or 4 way) joins in Rails (where the join tables
contain extra data as well.)
Let me give you my basic entities:
foos
id - pk
name - unique
bars
id - pk
name - unique
bazs
id - pk
name - unique
frozs
id - pk
name - unique
then i have two separate join tables:
foos_bars_bazs - 3 way join
2006 Feb 21
7
Self-referencial habtm relationship
Heyo!
I am setting up a self-referencial habtm relationship with the users
of my app. I am using Chad Fowler''s "Rails Recipes" to get me started,
and everything works great with the join table "people_friends". I add
friends by doing somebody.friends << somebodyelse. However, with my
app, there is an approval process so my join table has columns
person_id,
2006 Mar 19
1
How to access atributes from a join table?
I have a table "domains", "users" and a join table of "domains_users"
which has the domain_id, user_id as well as a userlevel_id attribute.
I know that in the model User class I can set the value of this
attribute with a function that calls:
domains.push_with_attributes(domain, :userlevel => 1)
but how do I access the userlevel field so that I can use it later on?
--
Posted via http://www.ruby-forum.com/.
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 < ActiveRecord::Base
[...]
has_and_belongs_to_many :child_documents, :class...
2006 Jan 04
2
Updating Attributes in a HABTM Join Table
...ists in the join
table.
def add_category( category_id_as_str )
category = Category.find(category_id_as_str.to_i)
if self.categories.include?(category)
old_count = self.categories.find(category.id).cat_count.to_i
self.categories.delete(category)
else
old_count = 0
end
self.categories.push_with_attributes(category, :cat_count =>
old_count + 1)
end
It seems like there should be a way to update the join instead of
deleting and recreating it. I know I could always turn the join into
a model--I''ve done that before but it seems like overkill for
something so simple as this. If it...
2005 Mar 08
1
Updating Join Attributes
Other than doing a raw SQL update the only way to update join
attributes is to remove an object and then push_with_attributes
correct?
--
Lon