Displaying 20 results from an estimated 1000 matches similar to: "habtm: attribute on join table"
2006 Jul 04
1
select(object, method, choices, options = {}, html_options = {})
Hi,
I''m using:
select(object, method, choices, options = {}, html_options = {})
I''ve read the API where there''s this example:
select("post", "person_id", Person.find_all.collect {|p| [ p.name,
p.id ] }, { :include_blank => true })
should give this code:
<select name="post[person_id]">
<option></option>
2006 Mar 13
3
HABTM: two habtm''s between the same two tables
Imagine I want to track people, and the clubs that they belong to.
table people with columns person_id, person_name
table clubs with columns club_id, club_name
And I have the association table:
table clubs_people with columns person_id, club_id
Now I know how to do this habtm between the two, in order to associate
people with clubs that they belong to.
However my application also needs a
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,
2005 Dec 31
6
habtm recursion via destroy_without_callbacks
I am having a problem with two models that each have a HABTM
relationship to the other. For example:
CREATE TABLE people (id INT, name TEXT);
CREATE TABLE teams (id INT, name TEXT);
CREATE TABLE people_teams (person_id INT, team_id INT);
The person model has:
has_and_belongs_to_many :teams
And the team model has:
has_and_belongs_to_many :people
The trouble comes when trying to destroy
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,
2008 Feb 20
0
HABTM problem
Hello,
I have two tables "people" and "relations"
Following are the models
class Person < ActiveRecord::Base
has_and_belongs_to_many :relations
class Relation < ActiveRecord::Base
has_and_belongs_to_many :people
I want to select multiple relations and when i say
Person.create(params[:person]) in controller
the relation ids and and id of person should be stored in
2012 Nov 03
0
ids writer fields for HABTM relationship.
Hello forum readers,
Let''s say i have two models: Person and Role (i replicated the problem
with Post & Tag as well, as i thought the problem was linked to some
application-specific rights problem, but it wasn''t).
In Person, attr_accessible role_ids is declared, so it accepts an array
of Role ids as an argument when creating / updating.
If i fire up the rails console and
2006 May 26
3
Breakdowns in has_many abstraction
I discovered an interesting aspect of has_many behavior that I''m
struggling to work around. I''m not sure if I''m doing something wrong,
or if it''s a legitimate bug, or if it''s an inherent part of Rails that
I just have to learn to deal with.
It boils down to these two problems:
- changes in collection objects (i.e. models that belong_to a
container
2012 Oct 13
4
Database design, working but looking for better ways
Rails 3.1.3
Hi. I have designed the database used for my travel plan application.
You should be able to look at the diagram in the link below, hopefully.
https://cacoo.com/diagrams/biDSyxh8yzk2kIeg
("belongs_to" is omitted since it''s obvious)
Basically, the application can list the destinations from a choice of
the departure.
Not mention that the departure_id (integer) and
2009 Feb 27
4
Optimize for loop / find last record for each person
I want to find the last record for each person_id in a data frame
(from a SQL database) ordered by date. Is there a better way than
this for loop?
for (i in 2:length(history[,1])) {
if (history[i, "person_id"] == history[i - 1, "person_id"])
history[i, "order"] = history[i - 1, "order"] + 1 # same person
else
history[i,
2006 May 16
1
:conditions on has_one realationship
Hi there,
I''m currently building a membership application and I want to be able
to select, not just all the memberships, but the most current
membership from the database on a per user basis. I have linked the
tables as shown:-
class Membership < ActiveRecord::Base
belongs_to :payment
belongs_to :person
end
class Person < ActiveRecord::Base
has_many :memberships
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 Oct 02
2
when to use find_by_sql
I have a bunch of queries to compute some counters, like
find_by_sql(<<-SQL
SELECT p.*, c.nfavourites
FROM people p, (
SELECT fp.person_id, COUNT(fp.user_id) as nfavourites
FROM favourite_people fp, users u
WHERE fp.user_id = u.id
AND u.cluster = ''#{in_cluster_of_user.cluster}''
GROUP BY fp.person_id
) as c
WHERE
2006 Jun 26
2
n-way has_mant :through
I''m trying to setup some mildly complex associations for a project we''re
working on and can''t seem to find much documentation on n-way has_many
:through associations.
I have the following models: Person, PhysicalAddress, EmailAddress,
PhoneNumber.
Each person can have multiple PhysicalAddresses, EmailAddresses, and
PhoneNumbers, and multiple people can share the same
2006 Apr 05
13
scaffold misuse?
Running ruby script/generate scaffold Product Admin
is a wonderful way to set up well, exactly what it says, a scaffold.
My problem is that I have several other tables that are linked,
through foreign keys, to the Product table. Say an "authors" table.
Now when I go enter a new product, a book, I want the application to
provide a drop down list of authors generated from the records in
2006 Jul 13
2
having a problem with acts_as_state_machine
Hi all:
Below is s a dump from script/console in development env.
Am I not supposed to be able to find the record later and use the
state machine functionality, or have I missed something? Thanks
Forrest
----------------------------
>> ts2 = TalkSession.create( :person_id => 2, :pattern_id => 2)
=> #<TalkSession:0x35811f0 @attributes={"pattern_id"=>2,
2006 Jun 06
1
Please Help with single table inheritance relationships
I''ve been searching the web, wikis, and more, and I haven''t turned up
examples of how to have multiple entities in a single-table inheritance
related to anything.
I have an addresses table, but multiple entities can have Addresses:
both Person (which has 2 addresses) and Retailer. I''ve been told that I
need to use single-table inheritance, and this was my attempt:
2008 May 02
1
names of select elements inside a fields_for block not generated as expected
Hey All,
I''m trying to play along w/the ''complex forms 1'' railscast
(http://railscasts.com/episodes/73) and having trouble. The view is
projects/new. I''m trying to add some project_people to the form w/code
like so:
<% form_for(@project) do |f| %>
[project stuff here]
<% for pp in @project.project_person %>
<% fields_for
2006 Jan 09
3
Design Question
I am sure some of you can give me an insight into this. This is more
towards the database design for the scenario below:
Say for example,
I have a person table and this person can have different address types.
One could be Home and the other could be say Office.
Should be model this
Table people
id
fname
lname
Table addresses
id
person_id
addr1
addr2
....
or
Table people
id
fname
lname
2007 Jun 29
1
Speeding up :dependent => :destroy
I have a tree of models that represent a book. Looks like this:
book
sections
documents
paragraphs
index entries
glossary entries
footnotes
index entries
glossary entries
These are all models with has_many from parent and the child has
belongs_to. They also all have dependent => :destroy