Akelos Framework v1 forum archive. This forum is no longer maintained. To report bugs please visit https://github.com/akelos/akelos/issues
    • CommentAuthorkkrzyzak
     
    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
     

    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
     
    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
     
    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?