Welcome Guest, Not a member yet? Register   Sign In
Just a little explanation for a beginner...
#11

[eluser]Colin Williams[/eluser]
1. If you don't see a need for them, don't include them.

2. You want to do a JOIN query in the model, then, still in the model, iterate over the result and group multiple entries by the primary object's primary key field. This is nearly always the process for many-to-many relationships
#12

[eluser]knucklehead[/eluser]
[quote author="Colin Williams" date="1254973465"]1. If you don't see a need for them, don't include them.[/quote]
Understood! =)

[quote author="Colin Williams" date="1254973465"]2. You want to do a JOIN query in the model, then, still in the model, iterate over the result and group multiple entries by the primary object's primary key field. This is nearly always the process for many-to-many relationships[/quote]
OK, I understand that part and I am doing it in both my models, but let me try to explain what I meant;

I have an artist_model in which i get some array of artist(s) which was created with huge mysql query. With my 'formatting function' I make my artist 'object' with polished properties (some of them are strings, some arrays, etc). This is the thing you were saying about, right? Something like this:
Code:
private function format_artist($r){
    
    $a = array();
    foreach ($r as $artist){
        $a[$artist->artistID]['artistID'] = $artist->artistID;
        $a[$artist->artistID]['artistName'] = $artist->artistName;
        $a[$artist->artistID]['links'][$artist->artistLinkURL] = $artist->artistLinkURL;
        $a[$artist->artistID]['descriptions'][$artist->artistDescription] = $artist->artistDescription;
        $a[$artist->artistID]['categories'][$artist->artistCat] = $artist->artistCat;
    }
    return $a;
    
}

In my events_model I need to use another huge mysql query and I would like to avoid extending it with artist's huge query to retrieve everything I need. Instead of that, I imagine I could 'attach' those already formatted artist 'objects' to each event they belong to. After that, my final event array would have a property like 'event_artists' which would be some array of objects (already formatted artists). I'm not sure if is it smart to do it that way... I mean, is it hard to manipulate with such data later?

Thanks for help =)
#13

[eluser]Colin Williams[/eluser]
I would aim for a single JOIN query, but another option is to just run two queries and then iterate over one and do the logic in PHP to append artists to a property of the event objects. (Looks like all you are doing in your current code is converting object notation to array notation, and adding a dimension to the array)

Either way do it in your model. That way anytime your information/data needs change, you've got just one place to make changes to (the model).
#14

[eluser]knucklehead[/eluser]
[quote author="Colin Williams" date="1254975249"]I would aim for a single JOIN query, but another option is to just run two queries and then iterate over one and do the logic in PHP to append artists to a property of the event objects. (Looks like all you are doing in your current code is converting object notation to array notation, and adding a dimension to the array)

Either way do it in your model. That way anytime your information/data needs change, you've got just one place to make changes to (the model).[/quote]
Thanks for reply!
Yes, that's exactly what I am doing with my query results.
Thank you for clearing out some things to me =)
I couldn't resist to check out your Template Library so I think you will hear from me later =)
#15

[eluser]knucklehead[/eluser]
Hi! After a 'good' sleep I am trying to understand the logic you explained me, but I still have some small 'problem' with this =)

[quote author="Colin Williams" date="1254975249"]I would aim for a single JOIN query, but another option is to just run two queries and then iterate over one and do the logic in PHP to append artists to a property of the event objects. (Looks like all you are doing in your current code is converting object notation to array notation, and adding a dimension to the array)[/quote]

OK, if I use single JOIN or WHERE query in my events_model, I will have to format event data in one way and artist data in other way. But I already have my artist formatted in artists_model. So I would have to repeat the same code for formatting... Isn't there some way to get those already formatted artists from artists_model in events_model?

[quote author="Colin Williams" date="1254975249"]Either way do it in your model. That way anytime your information/data needs change, you've got just one place to make changes to (the model).[/quote]

OK, I do it in the model. You say that I will have to make changes in only one place if there will be need for it... But if I make everything like you said - in my events_model, and format my artists there, and if I will have to change that formatting for artist I will have to do it in 2 places; events_model and artists_model...

Thanks for your time, I really appreciate it =)




Theme © iAndrew 2016 - Forum software by © MyBB