This project is archived and is in readonly mode.

#4992 ✓committed
Jan Xie

new table name set by set_table_name not used by model

Reported by Jan Xie | June 28th, 2010 @ 09:11 AM

test case example:

class PostDraft < Post
  set_table_name 'post_drafts'
end

assert_difference("PostDraft.count") do
  Post.set_table_name 'posts'
  Post.create

  Post.set_table_name 'post_drafts'
  Post.create
end

Test will fail because the second Post.create will still insert into posts table instead of post_drafts table, but if you check Post.table_name you'll get 'post_drafts'. The correct behavior should be:

either A. insert into post_drafts table on the 2nd Post.create
or B. raise an error on the 2nd Post.set_table_name to keep consistence (if this is not a bug but a feature, lol)

(attached a patch for A)

Comments and changes to this ticket

  • Jan Xie

    Jan Xie June 28th, 2010 @ 09:16 AM

    • Tag changed from rails 3.0.0.beta4, table_name to activerecord set_table_name test, rails 3.0.0.beta4, table_name
  • Jan Xie

    Jan Xie June 28th, 2010 @ 09:16 AM

    • Tag changed from activerecord set_table_name test, rails 3.0.0.beta4, table_name to rails 3.0.0.beta4, table_name
  • Jan Xie

    Jan Xie June 28th, 2010 @ 10:38 AM

    table_name_prefix= and table_name_suffix= have the same problem too.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 05:01 PM

    • State changed from “new” to “open”
    • Tag changed from rails 3.0.0.beta4, table_name to rails 300beta4, table_name

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 05:01 PM

    • State changed from “open” to “stale”
  • Jan Xie

    Jan Xie February 3rd, 2011 @ 12:51 PM

    • State changed from “stale” to “open”
    • Tag changed from rails 300beta4, table_name to table_name

    Still exists in latest rails. I update the patch in attachment, including a test case.

    [state:open]

  • Jan Xie
  • Aaron Patterson

    Aaron Patterson February 3rd, 2011 @ 07:04 PM

    • State changed from “open” to “incomplete”
    • Importance changed from “” to “Low”

    AR tests fail when I apply this patch:

      1) Failure:
    test_raises_error(InvalidTableNameFixturesTest) [test/cases/fixtures_test.rb:447]:
    FixtureClassNotFound expected but nothing was raised.
    
  • Jan Xie

    Jan Xie February 4th, 2011 @ 02:13 PM

    • Assigned user set to “Aaron Patterson”

    The problem is class FunnyJoke added by patch is suppoesed to not exist, so FixtureClassNotFound will be raised.

    I renamed FunnyJoke to GoodJoke, now all passed. See below updated patch.

  • Jan Xie

    Jan Xie February 5th, 2011 @ 12:52 PM

    • no changes were found...
  • Jan Xie

    Jan Xie February 5th, 2011 @ 12:53 PM

    • State changed from “incomplete” to “open”

    [state:open]

  • Aaron Patterson

    Aaron Patterson February 8th, 2011 @ 06:33 PM

    • State changed from “open” to “committed”

    Applied and pushed, thanks!

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Tags

Pages