While I''m not currently using the whole rails environment, I may
utilize
the framework in the future. In the meantime, I''m not clear on the
syntax for establishing a foreign key relationship for an active record
association using "t.references" or "t.belongs_to":
thufir@ARRAKIS:~/projects/rss2mysql$
thufir@ARRAKIS:~/projects/rss2mysql$ rake migrate
(in /home/thufir/projects/rss2mysql)
== CreateSubscribers: migrating
=============================================-- create_table(:subscribers)
-> 0.0064s
== CreateSubscribers: migrated (0.0068s)
====================================
== PopulateSubscribers: migrating
============================================= PopulateSubscribers: migrated
(0.0443s)
==================================
== CreateSubscriptions: migrating
===========================================-- create_table(:subscriptions)
-- subscribers()
rake aborted!
An error has occurred, all later migrations canceled:
undefined method `subscribers'' for
#<ActiveRecord::ConnectionAdapters::MysqlAdapter:0xb74e78b8>
/home/thufir/projects/rss2mysql/rakefile:9
(See full trace by running task with --trace)
thufir@ARRAKIS:~/projects/rss2mysql$
thufir@ARRAKIS:~/projects/rss2mysql$ cat db/migrate/00
0010_create_subscribers.rb 0030_create_subscriptions.rb
0050_create_items.rb
0020_populate_subscribers.rb 0040_populate_subscriptions.rb
0060_create_pages.rb
thufir@ARRAKIS:~/projects/rss2mysql$ cat db/
migrate/0040_populate_subscriptions.rb
class PopulateSubscriptions < ActiveRecord::Migration
class Subscription < ActiveRecord::Base
end
def self.up
s1 = Subscription.create(:subscription =>
''http://groups.google.ca/
group/ruby-talk-google/feed/rss_v2_0_msgs.xml'',:subscriber_id => 1)
s2 = Subscription.create(:subscription =>
''http://www.slashdot.org/
index.rss'',:subscriber_id => 2)
end
def self.down
end
end
thufir@ARRAKIS:~/projects/rss2mysql$
thufir@ARRAKIS:~/projects/rss2mysql$ cat db/
migrate/0030_create_subscriptions.rb
class CreateSubscriptions < ActiveRecord::Migration
def self.up
create_table :subscriptions do |t|
#t.column :subscriber_id, :integer #, :null => false
t.references subscribers
t.column :subscription, :string
end
end
def self.down
drop_table :subscriptions
end
end
thufir@ARRAKIS:~/projects/rss2mysql$
is there an error with migration, or in how it''s used?
thanks,
Thufir
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
On Mon, Dec 21, 2009 at 9:40 AM, Thufir <hawat.thufir-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> While I''m not currently using the whole rails environment, I may utilize > the framework in the future. In the meantime, I''m not clear on the > syntax for establishing a foreign key relationship for an active record > association using "t.references" or "t.belongs_to": >3 things came to my mind as I read your post... 1) Upgrade to a later version of Rails. You don''t say what version you are using, but the convention of migrations named NNNN_some_name changed to YYYYMMDDHHMMSS_some_name about a year(ish) ago when I first started learning about Rails. 2) I wonder if you have a pluralization problem and if yuo should change your CreateSubscriptions class to use t.references subscriber instead of t.references subscribers. In general, I have learned that a "thing" model "has_many :somethings" (note the plural) while the Something model would "belongs_to :thing" (note the singular). 3) I also wonder why you commented out the creation of the primary key for your Subscriptions table, although that is not likely to be your problem. --wpd -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> thufir@ARRAKIS:~/projects/rss2mysql$ > > is there an error with migration, or in how it''s used? >well much like you write t.column :subscriber_id and not t.column subscriber_id, you need to write t.references :subscribers Fred -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Mon, 21 Dec 2009 11:39:01 -0800, Frederick Cheung wrote:>> is there an error with migration, or in how it''s used? >> >> > well much like you write t.column :subscriber_id and not t.column > subscriber_id, you need to write t.references :subscribersI went with t.references :subscriber as that worked better with my script: thufir@ARRAKIS:~/projects/rss2mysql$ thufir@ARRAKIS:~/projects/rss2mysql$ cat db/ migrate/0030_create_subscriptions.rb class CreateSubscriptions < ActiveRecord::Migration def self.up create_table :subscriptions do |t| #t.column :subscriber_id, :integer #, :null => false t.references :subscriber t.column :subscription, :string end end def self.down drop_table :subscriptions end end thufir@ARRAKIS:~/projects/rss2mysql$ which is correct, subscriber or subscribers? -Thufir -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Mon, 21 Dec 2009 14:16:51 -0500, Patrick Doyle wrote:> On Mon, Dec 21, 2009 at 9:40 AM, Thufir > <hawat.thufir-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> While I''m not currently using the whole rails environment, I may >> utilize the framework in the future.[...]> 1) Upgrade to a later version of Rails.I may use the framework at a later point, but for now am just using Active Record.> > 2) I wonder if you have a pluralization problem and if yuo should change > your CreateSubscriptions class to use > > t.references subscriber > > instead of > > t.references subscribers. In general, I have learned that a > "thing" model "has_many :somethings" (note the plural) while the > Something model would "belongs_to :thing" (note the singular).Yes, I seem to be having this problem, but I *seem* to have worked it out (see seperate post).> 3) I also wonder why you commented out the creation of the primary key > for your Subscriptions table, although that is not likely to be your > problem.Oh, only because rather than create it manually, I wanted to use this "references" feature. -Thufir -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Dec 24, 12:59 pm, Thufir <hawat.thu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Mon, 21 Dec 2009 11:39:01 -0800, Frederick Cheung wrote: > > which is correct, subscriber or subscribers? >subscriber (that was just a typo on my behalf - the main thing is that you need to be passing a string or symbol) Fred -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.