DataMapper ORM v1.8.0 |
[eluser]endielo[/eluser]
[quote author="WanWizard" date="1299367657"]What exactly are you trying to achieve with this query? It looks quite complicated to me, for the result it produces...[/quote] I m trying to answer Brainer question, the code i wrote may be too complicate, he just want a simple inner join with two related object. May be you are the most suitable person to solve his problem. Btw, I think why not to setup a separated forum for data mapper, now it is too difficult to get help and search post. -- Endie Lo
[eluser]WanWizard[/eluser]
As @brainer already mentioned, there are methods available to include related data, see http://datamapper.wanwizard.eu/pages/get...de_related. In the case of @BrendanRehman you can simply do Code: $u = new User(); In the case of @brainer, the answer is the same Code: $b = new Book(); As the manual says "This method can significantly reduce your query overhead.".
[eluser]IgnitedCoder[/eluser]
Perfect... I needed to use Code: ->include_join_fields() Next question is how would I include mutual connections Say user 1 and 4 are related and user 4 and 8 are related and user 8 and 1 are related.. I want to show the related connections as in (2) connections in common. Which is a link that shows the related connections in common. Any thoughts/suggestions are welcome. BTW - Very cool library, saved me having to write tons of SQL and I think with eAccel setup and a good server its going to FLY! Brendan
[eluser]endielo[/eluser]
[quote author="WanWizard" date="1299373804"]As @brainer already mentioned, there are methods available to include related data, see http://datamapper.wanwizard.eu/pages/get...de_related. In the case of @BrendanRehman you can simply do Code: $u = new User(); In the case of @brainer, the answer is the same Code: $b = new Book(); As the manual says "This method can significantly reduce your query overhead.".[/quote] i think @brainer problem is that the included is $has_many side , the doc said that "This method will only work with $has_one related models" also, the include_related it NOT filter out any book because it is a 'left outer join' so... directly use CI active record may be the other solution in this case -- Endie Lo
[eluser]WanWizard[/eluser]
You are right, I missed that. In case of the books, you could filter the results by excluding all NULL values of the foreign key. With the current development version (1.8.1-dev), on bitbucket, include_related() works on has_many relationships as well. That line in the docs has been replaced by "This method creates a full join on both tables. Make sure to use the appropriate WHERE clauses, and/or use DISTINCT, to limit the number of rows in the result!"
[eluser]endielo[/eluser]
[quote author="WanWizard" date="1299428129"]You are right, I missed that. In case of the books, you could filter the results by excluding all NULL values of the foreign key. With the current development version (1.8.1-dev), on bitbucket, include_related() works on has_many relationships as well. That line in the docs has been replaced by "This method creates a full join on both tables. Make sure to use the appropriate WHERE clauses, and/or use DISTINCT, to limit the number of rows in the result!"[/quote] OH... it is really COOL now ...
[eluser]Dennis Rasmussen[/eluser]
Done a lot of google searching, no result. How do you work with Datamapper + Pagination (preferably the CI library)? Ì'm sure the next one is simple, but not sure what method is the best. With two tables related as many:many with a join table, how do you select the content of table1 with a filter (where) on table2?
[eluser]WanWizard[/eluser]
Dennis, How about Code: $table1->where_related('table2', 'field', 'value')->get(); As for pagination, check out http://datamapper.wanwizard.eu/pages/getalt.html, get_paged() and get_paged_iterated().
[eluser]Dennis Rasmussen[/eluser]
WanWizard, Awesome. Does where_related and where_related_{model} only work for one field or do you either use an array or chain with another where_related on the same model?
[eluser]WanWizard[/eluser]
You can chain to your hearts content. Multiple where_related() calls will add the field to the WHERE clause using AND (unless you use or_where_related() ). |
Welcome Guest, Not a member yet? Register Sign In |