[typo] Cannot access content records from another rails application

Stan Shore stan at workflowinc.com
Tue Apr 1 19:31:09 EDT 2008


I have done this successfully with other 'foreign' databases, but it does
not seem to work with the Typo content table.  At least not the way I would
expect it to.

First I created a connection entry in database.yml:

typo_development:
  adapter: mysql
  database: typo_dev
  username: myusername
  password: mypassword
  socket: /tmp/mysql.sock
  encoding: utf8

Then I created an abstract ActiveRecord class to hold the connection:

class TypoBase < ActiveRecord::Base
    establish_connection "typo_#{RAILS_ENV}"
end

Then I created a descendant class to point to the table:

class TypoContent < TypoBase
  set_table_name 'contents'
  set_primary_key 'id'
end

When I go into the console and do a find, no records are returned even
though there are records in the table.  I get no errors however:

Loading development environment (Rails 2.0.2)
>> TypoContent.find(:first)
=> nil
>> TypoContent.find(:all)
=> []
>>

Now for the weirdest thing.  I can successfully add records to the table!
CocoaMySQL shows that they are added to the table.  Find then returns the
records that I added but continues to ignore any prior existing records.

Here is additional evidence that the connections are solid:

>> TypoBase.connection.tables
=> ["articles_tags", "blacklist_patterns", "blogs", "categories",
"categorizations", "contents", "feedback", "notifications", "page_caches",
"pings", "profiles", "profiles_rights", "redirects", "resources", "rights",
"schema_info", "sessions", "sidebars", "sitealizer", "tags", "text_filters",
"triggers", "users"]
>> TypoContent.table_name
=> "contents"
>> TypoContent.columns
=> [#<ActiveRecord::ConnectionAdapters::MysqlColumn:0x1a682f8
@type=:integer, @null=false, @scale=nil, @name="id", @default=nil,
@sql_type="int(11)", @precision=nil, @primary=true, @limit=11>,
#<ActiveRecord::ConnectionAdapters::MysqlColumn:0x1a6826c @type=:string,
@null=true, @scale=nil, @name="type", @default=nil,
@sql_type="varchar(255)", @precision=nil, @primary=false, @limit=255>,
#<ActiveRecord::ConnectionAdapters::MysqlColumn:0x1a68190 @type=:string,
@null=true, @scale=nil, @name="title", @default=nil,
@sql_type="varchar(255)", @precision=nil, @primary=false, @limit=255>,
#<ActiveRecord::ConnectionAdapters::MysqlColumn:0x1a680c8 @type=:string,
@null=true, @scale=nil, @name="author", @default=nil,
@sql_type="varchar(255)", @precision=nil, @primary=false, @limit=255>,
#<ActiveRecord::ConnectionAdapters::MysqlColumn:0x1a68000 @type=:text,
@null=true, @scale=nil, @name="body", @default=nil, @sql_type="text",
@precision=nil, @primary=false, @limit=nil>,
#<ActiveRecord::ConnectionAdapters::MysqlColumn:0x1a67f38 @type=:text,
@null=true, @scale=nil, @name="extended", @default=nil, @sql_type="text",
@precision=nil, @primary=false, @limit=nil>,
#<ActiveRecord::ConnectionAdapters::MysqlColumn:0x1a67e98 @type=:text,
@null=true, @scale=nil, @name="excerpt", @default=nil, @sql_type="text",
@precision=nil, @primary=false, @limit=nil>,
#<ActiveRecord::ConnectionAdapters::MysqlColumn:0x1a67df8 @type=:string,
@null=true, @scale=nil, @name="keywords", @default=nil,
@sql_type="varchar(255)", @precision=nil, @primary=false, @limit=255>,
#<ActiveRecord::ConnectionAdapters::MysqlColumn:0x1a67d58 @type=:datetime,
@null=true, @scale=nil, @name="created_at", @default=nil,
@sql_type="datetime", @precision=nil, @primary=false, @limit=nil>,
#<ActiveRecord::ConnectionAdapters::MysqlColumn:0x1a67c90 @type=:datetime,
@null=true, @scale=nil, @name="updated_at", @default=nil,
@sql_type="datetime", @precision=nil, @primary=false, @limit=nil>,
#<ActiveRecord::ConnectionAdapters::MysqlColumn:0x1a67bf0 @type=:integer,
@null=true, @scale=nil, @name="user_id", @default=nil, @sql_type="int(11)",
@precision=nil, @primary=false, @limit=11>,
#<ActiveRecord::ConnectionAdapters::MysqlColumn:0x1a67b50 @type=:string,
@null=true, @scale=nil, @name="permalink", @default=nil,
@sql_type="varchar(255)", @precision=nil, @primary=false, @limit=255>,
#<ActiveRecord::ConnectionAdapters::MysqlColumn:0x1a67a88 @type=:string,
@null=true, @scale=nil, @name="guid", @default=nil,
@sql_type="varchar(255)", @precision=nil, @primary=false, @limit=255>,
#<ActiveRecord::ConnectionAdapters::MysqlColumn:0x1a679c0 @type=:integer,
@null=true, @scale=nil, @name="text_filter_id", @default=nil,
@sql_type="int(11)", @precision=nil, @primary=false, @limit=11>,
#<ActiveRecord::ConnectionAdapters::MysqlColumn:0x1a678f8 @type=:text,
@null=true, @scale=nil, @name="whiteboard", @default=nil, @sql_type="text",
@precision=nil, @primary=false, @limit=nil>,
#<ActiveRecord::ConnectionAdapters::MysqlColumn:0x1a67830 @type=:string,
@null=true, @scale=nil, @name="name", @default=nil,
@sql_type="varchar(255)", @precision=nil, @primary=false, @limit=255>,
#<ActiveRecord::ConnectionAdapters::MysqlColumn:0x1a67790 @type=:boolean,
@null=true, @scale=nil, @name="published", @default=false,
@sql_type="tinyint(1)", @precision=nil, @primary=false, @limit=1>,
#<ActiveRecord::ConnectionAdapters::MysqlColumn:0x1a676c8 @type=:boolean,
@null=true, @scale=nil, @name="allow_pings", @default=nil,
@sql_type="tinyint(1)", @precision=nil, @primary=false, @limit=1>,
#<ActiveRecord::ConnectionAdapters::MysqlColumn:0x1a675b0 @type=:boolean,
@null=true, @scale=nil, @name="allow_comments", @default=nil,
@sql_type="tinyint(1)", @precision=nil, @primary=false, @limit=1>,
#<ActiveRecord::ConnectionAdapters::MysqlColumn:0x1a674fc @type=:datetime,
@null=true, @scale=nil, @name="published_at", @default=nil,
@sql_type="datetime", @precision=nil, @primary=false, @limit=nil>,
#<ActiveRecord::ConnectionAdapters::MysqlColumn:0x1a67448 @type=:string,
@null=true, @scale=nil, @name="state", @default=nil,
@sql_type="varchar(255)", @precision=nil, @primary=false, @limit=255>]
>>

I really like Typo and want to use it to create blog entries, but I need to
show those entries embedded in a different rails app.  I thought it would be
a piece of cake and have no clue what is going on here.  Any help would be
appreciated.

Stan Shore
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/typo-list/attachments/20080401/feb1161e/attachment.html 


More information about the Typo-list mailing list