[Deprecated] DMZ 1.6.2 (DataMapper OverZealous Edition) |
[eluser]Oblique[/eluser]
At the same time, i encountered some strange behaviour On my dev WAMP this worked fine (MYSQL ver. = 5.0.45 if it matters somehow): Code: $this but in production LAMP (MYSQL ver. = 5.0.89) it made this crap: Quote:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`users_subquery`.id = `users`.`id`) AS created_freightage_count FROM (`users`) L' at line 4
[eluser]OverZealous[/eluser]
[quote author="bobosayhello" date="1266618591"] That is, why does DMZ require the use of an extra joining table even when there is just a one-to-many relationship between two tables? What's the problem with the traditional approach of having a foreign key in the table of 'many' and making it refer to the primary key in the table of 'one'?[/quote] As mentioned earlier, it does not require an extra table. DMZ handles In-Table Foreign Keys, which it says on the first page of the manual ;-), as well as under <a href="http://www.overzealous.com/dmz/pages/database.html">Database Tables</a> (see the bottom). DMZ is based upon the older DataMapper by stensi, and his design required full Fifth-normal form compliance. Obviously that has negative performance and database complexity side effects, which was one of the original factors for forking DataMapper. (Well, is it really a fork if the original has not been updated?) There is an awesome new release coming soon (probably early next week), but the changes are mostly performance and new-features based, so the upgrade from 1.6.2 to 1.7.0 should be very smooth.
[eluser]OverZealous[/eluser]
[quote author="NachoF" date="1266624303"] But for some reason when I try to access its properties elsewhere in my app I get Quote:Message: Trying to get property of non-object error[/quote] I'm guessing you are coming across this error or you have a database field name or related field that overides a Reserved Name. (There's a reason for the list at the top of the Troubleshooting page.) Remember, there are no namespaces in PHP (<6.0), which means there can only be one class per name. This means that you cannot have a model named Session if you have a library named Session. (MY_Session and CI_session are OK, though.)
[eluser]OverZealous[/eluser]
@Oblique It looks like your LAMP server has an outdated version of DMZ. Make sure all of the files are synced. The subquery-based bug you are seeing was fixed in 1.6.2.
[eluser]NachoF[/eluser]
Heres my login function Code: function login()
[eluser]OverZealous[/eluser]
@NachoF :ahhh: You can't put a DataMapper object into the session! That would store: - Two copies of the entire Object, each of which references - All of the data that DMZ uses to manage the object: - The entire CI DB object - The entire CI Language object - The entire CI Loader - Probably much, much more - Now recursively apply this to every related object that is loaded on that User. If you have any autoloading, this could actually cause an infinite loop. Just store the ID of the user in the session, and pull it from the database each time. It's a ridiculously fast query, since it is a primary key lookup. (If the session is not in the database, then make sure the cookie is encrypted!) PHP is completely stateless, so there is really no practical way to store objects between requests.
[eluser]NachoF[/eluser]
Ok, I just thought that it would be more practical to store the complete object in the session.. I just came back to CI after working in asp.net mvc and just thought I would use the same approach of storing the complete logged in user object in the session instead of just the id... but that would do. thanks
[eluser]OverZealous[/eluser]
@NachoF I understand completely. I used to write code almost exclusively in Java, and Java servers also have sessions with long-term in-memory objects. (Plus they have that cool way of storing the session ID inline in the URL, so it works without cookies. But I digress...) But even so, the way DataMapper works, it might not be very sensible on that kind of server, because the DMZ model retains connections to the database, among other objeects. Also, you would then have to worry about stale data (ie: the user changes their name, and now the session model is incorrect, etc). Just a hint: I extend the CI Session class to handle loading my user automatically. Basically, after the session is initialized, you can then see if a User ID exists, and if so, load the User automatically, and store it on the session object. If you want to use lazy-loading, do it like this: Code: class MY_Session extends CI_Session { Code: if($this->session->get_user()) {
[eluser]BaRzO[/eluser]
Hi all, I haven't do this a have a model region and a region can have many city and a city can have one region... my database citeis table id | name | region_id regions table id | name | status city model => var $has_one = array('region'); region model => var $has_many = array('city'); how i can pull all regions and regions cities like this regions a |____ city 1 |____ city 2 region b |____ city 4 |____ city 9 pls help me i haven't figure it...
[eluser]OverZealous[/eluser]
@BaRzO You might be able to do it in a single query, but you have to think about it backwards: Code: $city = new City(); The next release of DMZ has a method to specifically handle large queries, which might be useful if you have a lot of cities. |
Welcome Guest, Not a member yet? Register Sign In |