Not signed in (Sign In)
Welcome Guest!
Want to take part in these discussions? If you have an account, sign in now.
If you don't have an account, apply for one now.
    • CommentAuthorkkrzyzak
    • CommentTimeJun 16th 2009 edited
     
    Hi
    I would like to implement habtm relationship in my application between two models : Player and News.
    Each news could have assigned many players, and each player could have many news.
    I've got table players with primary key id, the same in news. As I know, I should create table, with associations between this two tables- but where I should declare it's name? I would be very greatful for any hints
    ---------
    Sorry for my language errors, English isn't my native language
    •  
      CommentAuthorbermi
    • CommentTimeJun 17th 2009
     

    The join table is created for you by Akelos the first time you load the association

    class Player extends ActiveRecord{
        public $habtm = 'news';
    }
    
    class News extends ActiveRecord{
        public $habtm = 'players';
    }
    

    There is one concern here, News is irregular and its singular is the same as it's plural, so try to manage this association from the Player association handler.

    $News = new News();
    $News->player; // is the association handler
    $News->player->load(); // loads associated elements. At this point it will create a news_players table for you
    $News->players; // holds associated elements
    

    I hope you find it useful

    • CommentAuthorkkrzyzak
    • CommentTimeJun 17th 2009
     
    Hi Bermi
    I'm trying now with many-to-many relationship (http://akelos.org/wiki/many_to_many_without_habtm)
    I've got 3 models:
    Player (id,name,age, (...))
    Player_relationship(id,player_id,cadre_id)
    Cadre(id,name)

    and code:
    cadre.php / player.php
    var $has_many = array('player_relationships'=>array('dependent'=>'destroy'));
    player_relationship.php
    var $belongs_to = array('cadre','player');
    and I'm trying to list all players for each cadre, and (in other controller) all cadres for each player.
    • CommentAuthorkkrzyzak
    • CommentTimeJun 18th 2009
     
    ok, disregard my last post, problem solved :)
    but now, I've got new:
    Let's say, that I want to create(or edit) player.
    I would like to list checkbox for each cadre - and automatically create(or delete, if I'm editing player, and check off some checkbox) new relationship (it's done in cadres_players table). I have to do it manually ? or is there any way to do it auto magically?
Add your comments
    Username Password
  • Format comments as