Akelos Framework v1 forum archive. This forum is no longer maintained. To report bugs please visit https://github.com/akelos/akelos/issues
    • CommentAuthorhpatoio
    Is find_by_sql working ?

    I've tried but I get

    > Fatal error: Call to undefined method Topic::find_by_sql() in ...

    Is this feature going to be released ?

    • CommentAuthorKaste

    thats findBySql in Akelos.

    most functions are camelCased

    • CommentAuthorhpatoio

    Thank. found the function but I don't get the expected results

    if my controller I have :

    function myTest() { $this->topics =& $this->Topic->findBySql("SELECT T.id, T.title, count(*) as feeds_number FROM topics AS T INNER JOIN feeds as F ON T.id = F.topic_id GROUP BY id, title"); }

    then in the view

    {loop topics} Title: {topic.title} n topics : {topic.feeds_number} {end}

    the point is that topics do not have feeds_number property.

    I had a fast look at findBySql and it seems that getOnlyAvailableAttributes returns the table attibutes and not those in the SQL.

    Am I wrong or is this a bug ?

    -- Simone

    • CommentAuthorKaste

    You're right.

    • CommentAuthorhpatoio

    Ok, that's already something.

    I'm trying to fix this.

    Actually I taught that was enough to replace

    $objects[] =& $this->instantiate($this->getOnlyAvailableAttributes($record), false);


    $objects[] =& $this->instantiate($record, false);

    But it doesn't work.

    In the AkActiveRecord constructor I get the correct parameters, but the object is still created just with those of the table.

    Hints ?

    -- Simone

    • CommentAuthorKaste

    ->setAttributes filters unknown attributes. (not columns nor so called combined attributes)

    • CommentAuthorteo
    could you please explain with an example how can i use setAttributes() to get the attributes of an inner join sql query
    • CommentAuthorKaste

    Can you be more specific? I don't get your question.

    • CommentAuthorjan.bartos
    I am solving quite similar problem:

    I have entity Member and entity Expedition. Each member is in some expedition and expedition can contain 0..n members. Now I want to enhance my listing view of Expeditions with information, how many members each expedition has. And I want this "syntetic" attribute to behave like original column present in table Expeditions (e.g. to have sortable column header). Sometimes I want display listing items (with attributes scattered among more tables) which can be simply and effectively retrieved (and filtered/sorted/paginated) by simple SQL select with joins. Unfortunately, not all joins can be made with simple using of 'include' option. Is it possible to create model with attributes stored in more DB tables? Or is it possible to alter sql query which retrieves model data? I do not neet the model to be writable.

    For now I solve such situations by adding columns with precalculated values which are difficult to maintain. Any suggestions?