Displaying 20 results from an estimated 3000 matches similar to: "problem when looping through habtm children in a view"
2005 Dec 30
5
HABTM with finder_sql problem (Rails bug?)
I''m building an app that needs i18n support across the entire database
(i.e. localized attributes). In order to do this I''ve created a
special HABTM join table that can be associated with _any_ other
table:
create table language_strings (
for_table varchar(255) not null,
foreign_id int not null,
language_id varchar(5) not null,
attr_name varchar(255) not null,
value text
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 Jan 04
5
habtm recusive
I have a people table:
CREATE TABLE people (
id int(10) unsigned NOT NULL auto_increment,
first_name varchar(75) default NULL,
middle_name varchar(75) default NULL,
last_name varchar(75) default NULL,
PRIMARY KEY (id)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1272 ;
and a people_people table:
CREATE TABLE people_people (
person_id int(11) unsigned NOT NULL,
2006 May 08
8
enforcing special behavior of child rows in HABTM
Hi,
I have a scenario where a doctor can have one or more specialties.
For each doctor, one and only one of her specialties can be designated
as primary.
So I have tables called doctors, specialties, and doctors_specialties,
the last of which has a boolean is_primary column.
The doctor model class specifies that:
has_and_belongs_to_many :specialties
I want to enforce, at the lowest possible
2006 Mar 29
2
inserts now set unset columns to null
Hi,
I upgraded to Ruby 1.8.4 and whatever the latest Rails is as of March 29
2006.
I am using PostgreSQL 7.4.
With the earlier version of rails, I had insert queries that looked like
this:
Topic Create (0.001189) INSERT INTO topics ("inlibrary",
"irx_display_title", "irx_title", "title", "creation_stamp",
"last_update_stamp",
2005 Dec 27
3
Trouble combining :has_many, :finder_sql and :conditions to create a sub-search
I''m sure there''s something right under my nose that I''m missing. I
have two tables with two parallel one-to-many relationships. I wish to
use the :finder_sql parameter to essentially ''or'' the two foreign
keys.
What isn''t working for me is performing a ''sub-search''.
Let''s say the tables are "stores" and
2006 Feb 28
3
[AR] #{id} namespace visibility used in finder_sql
Dears,
[Rails 1.0.0]
I''m working with a legacy schema, and around my 20+ models i''ve used
some AR constructs.
They are based on a finder_sql doing some dirty sql and using #{id}
from the ''pivot'' model for extracting data in other tables.
like :
class Division < ActiveRecord::Base
set_table_name "legacy_division"
set_primary_key
2005 Dec 18
1
problems with text_field_with_autocomplete
I''m trying to set up a search field with autocomplete. I have verified
that the server is called when I type a letter in the box, and that the
handler creates the correct instance variable. However, I never see the
partial that is supposed to be rendered.
Here are the relevant files. I included their paths/names in case I am
missing some nuance of the naming conventions.
2005 Dec 16
12
validates_presence_of not working
Hi,
I''m new to ruby and rails. I just created a simple update page and the
update works fine if all form fields are filled in. However there is one
field that should never be allowed to be blank. So I put this in my
model:
class Topic < ActiveRecord::Base
validates_presence_of :dr_title
validates_length_of :dr_title, :minimum => 1
So, when I submit the form with a blank
2005 Dec 24
3
Avoiding HABTM field clobbering?
>From the docs:
"Note that any fields in the join table will override
matching field names in the two joined tables. As a
consequence, having an "id" field in the join table
usually has the undesirable result of clobbering the
"id" fields in either of the other two tables."
I do have an ID field in the join table, and as a
result it''s clobbering the ID
2005 Dec 29
4
Many-to-Many: Where to add the children?
I have two classes Person and Job defined as follows:
class Person < ActiveRecord::Base
:has_and_belongs_to_many jobs
def add_job(job_name)
job = Job.find_by_name(job_name) # See if this job exists
if job.nil? # If this job doesn''t exist
job = Job.new # Create a new job
job.name = job_name #
2006 Jun 16
3
Does HABTM support non "id" FKs?
Quick question. Say I have a geographical database with counties and zip
codes where counties have and belong to many zip codes.
zip_codes (id, zip_code)
counties (id, name)
When I create the association table, the Rails way says to do the
following: counties_zip_codes (county_id, zip_code_id).
However, given that zip_codes.zip_code is itself a candidate key, I
would much prefer to do the
2006 Jan 04
2
Updating Attributes in a HABTM Join Table
Is there a way to update attributes in a HABTM join table? Right now
I am deleting the join and then recreating it with new attributes.
I have a table "categories" and another table "items". They are both
HABTM with the join table "categories_items" between them. If an item
is joined to a category once, no problem, we create the join. But if
an item is
2006 Feb 21
3
HABTM :insert_sql help
Hi all,
I''m working with a legacy sqlserver db and I''m trying to override the
insert sql in as defined in the HABTM method below(becasue the join
has three primary keys), but I''m getting the error: ''undefined local
variable or method `record'' for Project:Class''
has_and_belongs_to_many :people,
:class => ''Person'',
2005 Dec 15
2
HABTM being tricky
I''ve just been bodyslammed by a problem with has_and_belongs_to_many -
as far as I can tell, if it doesn''t appear at the top of other
relationship definitions it doesn''t seem to work right. For example:
class Artist < ActiveRecord::Base
has_and_belongs_to_many :genres
has_many :albums
has_many :videos
has_many :cds
has_many :collections
end
..works fine
2006 Jan 12
2
ActiveRecord models w/ base condition
Does anyone know how to do the following? I have 3 different AR classes
that all map to the same table. The only difference between this AR classes
is that they should only return record that match a certain condition.
For example, Foo should only return records from table ''list'' that follow
the condition ftype="foo", where as Bar, on the other hand, should only
2006 Feb 15
5
strange behavior with has_many and size
Here is a "ruby script/console" session verbatim which will explain the
problem. Bear in mind that nothing is changing the database behind the
scenes at any time. topics is a has_many relationship of Sponsor.
>> s = Sponsor.find(3)
=> #<Sponsor:0x22fd804 @attributes={...
>> s.topics.size
=> 1
>> l = s.topics
=> [#<Topic:0x22d3fa4 @attributes={...
2006 Jun 13
4
When saving parent fails, children will still be updated
Hi all,
When submitting a master/detail form I first want to handle the children
before saving the parent.
There are has_many and belongs_to relations between the parent and the
children, so I can edit the children using (psuedo-)code like:
child.destroy for deleting, child.update_attributes for updating and
@parent.children.push(child) for adding child-records.
I update the parent by using:
2006 Feb 15
5
dispatch.cgi error affecting specific browsers
I have a rails app that is accessed through Apache 2 (just using cgi
now; will add fastcgi later when everything is working).
The app works fine with some os/browser combos at my work site:
windows/IE
Mac/safari
Mac/firefox
Linux/firefox
But it fails on windows/firefox and my colleague''s (at a different site)
mac/safari (we are running the same os version and version of safari)
The
2008 Dec 13
3
how to do "special queries" ala The Rails Way on "associated" conditions?
I have the following in a model class:
class Game < ActiveRecord::Base
has_many :player_stats
has_many :players, :through => :player_stats
def visitor_stats
stats = []
player_stats.each do |stat|
stats << stat if stat.player.team.team_code ==
self.visiting_team_code
end
stats
end
def home_stats
stats = []
player_stats.each do |stat|
stats << stat if