#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2008
    Posts
    173
    Rep Power
    37

    Rails ActiveRecord and CakePHP interoperation


    In the interests of "using the right tool for the right job", I am using the Rails activerecord library and CakePHP to interact with the same database tables.

    In the main, these two are largely interoperable - they use the same conventions for relationships between tables, otherwise it would be a no-go.

    Where it falls down is the Rails use of "created_at" and "updated_at" while CakePHP uses "created" and "updated" or "modified".

    Is it possible with rails or with cake to change the names of the automagic model fields without resorting to hacking the core code?

    If mysql supported aliases for fields within the table structure also, that would be excellent!

    Cheers,

    Paul
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2004
    Location
    Constant Limbo
    Posts
    989
    Rep Power
    363
    If you are just looking to rename/alias a method, ruby supports this.
    Code:
    irb(main):001:0> class Array
    irb(main):002:1> alias_method :my_each, :each
    irb(main):003:1> end
    => Array
    irb(main):004:0> a = [1,2,3,4,5]
    => [1, 2, 3, 4, 5]
    irb(main):005:0> a.my_each { |x| puts x }
    1
    2
    3
    4
    5
    => [1, 2, 3, 4, 5]
    irb(main):006:0>
    Realize that I know nothing of Rails or Cake, but it sounds like this is what you were looking for. Feel free to ignore if I completely missed the mark
    True happiness is not getting what you want, it's wanting what you've already got.

    My Blog
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2008
    Posts
    173
    Rep Power
    37
    Yeah, that is handy, but I am not sure that I can use it in this case.

    I would imagine the ORM would make the class names and table column names the same, I don't think aliasing one would make it choose a different column name down in the depths of the class heirachy...

IMN logo majestic logo threadwatch logo seochat tools logo