# Permalink\_fu and classes with different primary\_key than id?

**URL:** <https://www.ruby-forum.com/t/permalink-fu-and-classes-with-different-primary-key-than-id/148869>\
**Category:** Rails\
**Created:** [September 17, 2008, 8:56pm UTC](https://www.ruby-forum.com/t/permalink-fu-and-classes-with-different-primary-key-than-id/148869 "2008-09-17T20:56:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![phil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e95f7d/32.png) [@phil](https://www.ruby-forum.com/u/phil)\
**Post date:** [September 17, 2008, 8:56pm UTC](https://www.ruby-forum.com/t/permalink-fu-and-classes-with-different-primary-key-than-id/148869/1 "2008-09-17T20:56:25Z")

</div>

Has anyone else had problems with this scenario?

class Team \< ActiveRecord::Base

# Primary key

self.primary\_key = ‘team\_id’

has\_many :players, :foreign\_key =\> :team\_id

has\_permalink :city, :param =\> true  
end

I am getting all kinds of trouble - that goes away if I comment out  
the has\_permalink declaration.

With PermalinkFu:

> > fs = Team.new  
> > =\> #\<Team team\_id: nil, abbr: nil, city: nil, created\_at: nil,  
> > updated\_at: nil, permalink: nil\>
> 
> > fs.team\_id = 1  
> > NoMethodError: undefined method `team_id=' for #<Team:0x2af1173c6030> from ~/20080917172814/vendor/rails/activerecord/lib/active_record/ attribute_methods.rb:251:in`method\_missing’  
> > from (irb):8  
> > from :0

without it just assigns the correct value to team\_id

The real bizarness comes here:

> > fs.id = 1  
> > =\> 1
> 
> > fs  
> > =\> #\<Team team\_id: 1, abbr: nil, city: nil, created\_at: nil,  
> > updated\_at: nil, permalink: nil\>

How does this happen?

This is all well and good except that these things fail:

> > record = Team.find\_or\_create\_by\_team\_id(1)  
> > NoMethodError: undefined method `team\_id=’ for #Team:0x2af1173b2418

Help!
