CodeIgniter Forums
[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: [Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) (/showthread.php?tid=18196)



[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 09-28-2009

[eluser]bEz[/eluser]
OUCH! Well, the likelihood of resolving this issue will be in rechecking your DMZ version (including files used: library, config, etc.), as well as, you model setup, controller code (any code called prior for example).
PHIL is patient with this, but most of these issues are either in the Troubleshooting area, or somewhere in previous threads of this post.

I'll keep an eye out, as I know once you resolve this, you will feel accomplished in your choice to use DMz! Wink

Not that this is a cause, but I see a Many to Many relationship being setup between Country and Inventory.
Check your DB setup, join_tables versus ITFK (In-Table Foreign Keys)

Another thing, Comment out the Inventory relationship in the Country model.


[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 09-28-2009

[eluser]KSiimson[/eluser]
Thanks for all the help so far!! I found a really strange behavior, which I think might be somehow related.

Code:
$country->order_by("printable_name", "asc");
$country->get();
echo $country->all->printable name;
Zimbabwe

Code:
$country->order_by("printable_name", "asc");
$country->get("1");
echo $country->all->printable name;
Afganistan

Code:
$country->order_by("printable_name", "asc");
$country->get("2");
echo $country->all->printable name;
Albania

Code:
$country->order_by("printable_name", "desc");
$country->get();
echo $country->all->printable name;
Afganistan

Code:
$country->order_by("printable_name", "asc");
$country->get("5");
echo $country->all->printable name;
Andorra

Perhaps I should create a separated thread for all that?


[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 09-28-2009

[eluser]bEz[/eluser]
In this case, you would not use ->all to get the item with id (5).
just do:
Code:
// order_by would be useless if providing an id.
$country->get_by_id(5);  
// no need for the double-quote, also either select('id') then get(), or get_by_id()
echo $country->printable_name;



[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 09-28-2009

[eluser]KSiimson[/eluser]
I really hate to admit that, but the error actually was that I didn't have DataMapper OverZealous Edition installed correctly (don't ask). Good part is that everything works now. Smile


[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 09-28-2009

[eluser]OverZealous[/eluser]
[quote author="Jinkusu" date="1254194137"]The weird thing is that field has nothing to do with the DB id, its suppose to be a automatically generated id number (like on your ID card at College). I've already changed it to student_number.[/quote]

The reason you are having trouble is that <model>_id is kind of a magic column name that DMZ uses for in-table foreign keys. You could also have use studentid, and not had a problem.

I'm surprised that DMZ was trying to use it, since it isn't a $has_one relationship, but I don't have time to dig through the code right this minute! Smile


@KSlimson

I'm glad to see you've worked it out! :-)


@bEz

Thank you for helping KSlimson!

I used a lot of exclamation points in this post! :lol:


[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 09-29-2009

[eluser]bEz[/eluser]
[quote author="KSiimson" date="1254200612"]I really hate to admit that, but the error actually was that I didn't have DataMapper OverZealous Edition installed correctly (don't ask). Good part is that everything works now. Smile[/quote]

Good...good! :cheese:

Using the correct DMz version is 33% of the issues I see as the culprit.
Another 33% is the setup of relationships in the model.
Yet another 33% is the controller code.
Finally, less than 1% is DMz itself.

All these figures are skewed, but you get the point. Wink


[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 09-29-2009

[eluser]Jinkusu[/eluser]
Brand new issue (at least to me)

I need to restrict the results of a query from a particular table where the result should be the intersection of two diff objects related to it. EG.

User has many Course and Course has one User
Term has many Course and Course has one Term

I need to find all the courses for a particular user where the course is available(related) for a specific term.

any suggestions on how to cross match and narrow down an object result like this?


[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 09-29-2009

[eluser]bEz[/eluser]
Try this snippet out (untested):
Code:
$term_id = ...
$user_id = ...

$t = new Term();
$t->get_by_id($term_id);

$c = new Course();
$c->where_related($t);

$u = new User();
$u->where_related($c)
    ->get_by_id($user_id);

DMz Manual :: Get (advanced)


Code:
if ( in_array($this->input->post('thread_smiley', $smilies) ) {
  print $this->input->post('thread_smiley') . br() . $this->input->post('message') ;
} else {
  echo $smilies['question'] . br() . $this->input->post('message');
}
$this->session->set_flash('thread posted!');



[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 09-29-2009

[eluser]OverZealous[/eluser]
@Jinkusu, bEz

bEz's code might work, but I think it makes more sense to do it this way:
Code:
// see manual for this style constructor, under DataMapper Models
$term = new Term($term_id);
$user = new User($user_id);

$courses = $u->course->where_related($term);

This will load all courses for a particular user, where they are also related to a specific term. Alternatively, and this really is the same thing, you could do this:
Code:
$courses = new Course();
$courses->where_related($user)->where_related($term);

Don't forget you can add other query options to your search, as well.


[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition) - El Forum - 09-29-2009

[eluser]Jinkusu[/eluser]
[quote author="bEz" date="1254270713"]Try this snippet out (untested):
Code:
$u = new User();
$u->where_related($c)
    ->get_by_id($user_id);
[/quote]

This line doesn't work as it just resets the relationship between the user and the course.

@OverZealous

Code:
$courses = new Course();
$courses->where_related($user)->where_related($term);

Works perfectly.

Thanks guys, ur making my life way easier, i'd buy ya'll a drink and call a cab for ya if i knew ya'll!