Kohana ORM Result - How to display? - string

Maybe something really simple, I got really big problem with... ORM result.
I'm loading object with relation using with(). It generates following query:
SELECT `article`.`id` AS `article:id`, `article`.`name` AS `article:name`
Now's my question... how to display article name in the view? Sorry for dumb question, I really can't beliebe I'm asking it.
Edit
Here's my code:
$activity = $user->activity->with('article')->where('article.status', '=', 1)->find_all()->as_array();
Relations are correct for sure. I can swear I saw something similar today morning on the Kohana Forums however cannot find it.
Cheers!

I haven't tested it but does it work if you do this:
$activities = $user->activity->with('article')->where('article.status', '=', 1)->find_all();
foreach($activities as $activity) {
echo $activity->name.'<br />';
}

Related

Sequelize Tables (Beginner Question) Node.js

Ok so I just started looking into databases yesterday
index.js: https://hatebin.com/pvqnubsrrs
database.js: https://hatebin.com/csgvmvolfz
I just want it to insert into the DB,
how would I accomplish that?
Someone told me it's creating a new DB, but when I run the command it says the table doesn't exist
The error says:
Error: SequelizeDatabaseError: SQLITE_ERROR: no such table: PointsSystems
However, I cannot find a spot in the code where I use PointsSystems, I only use PointsSystem, without the s
Edit: Thank you SigFried for making this more readable.
The error says PointSystems because, by default, Sequelize will pluralize the name you gave to the table. Your code looks O.K, the only missing part and the solution to your problem is the await sequelize.sync({ force: true })}. I made a little example to show you how it's done in a very basic way.
You should be able to find out why the sequelize.sync() methods is needed if you read this.

MongoDB/Express Query Object from URL

Sorry in advance for what I'm sure is going to be really straightforward. My brain is just not seeing it.
I have a database. I'd like to query that database from the frontend, using the arguments in my URI. We're not at that part yet. Express/Node on the back.
When I use this query:
dbo.collection("archive").find({OBJECT: 'RRP68'},{ projection: {
I get some results, as expected, of entries featuring that object. When I try this:
var query = {OBJECT: 'RRP68'};
dbo.collection("archive").find({query},{ projection: {
I get no results. Initially I thought the problem was how I consumed the URI element, then I thought scoping (even though pagination works fine in the same manner), but this is the most simplified version I could come up with that still didn't work. So clearly there's some syntax or structure concept or something along those lines I don't know, and can't seem to find in the docs.
Pointers would be appreciated.
It's because this is what is happening right now
dbo.collection("archive").find({{OBJECT: 'RRP68'}},{ projection: {
Do you see it? It's because of double curly brackets
This Will fix it
var query = {OBJECT: 'RRP68'};
dbo.collection("archive").find(query,{ projection: {

Retrieve all records of model (ORM2, nodejs)

Using the ORM2 module in Node.js, after creating a connection and checking that works, I can't find a way to retrieve all the records of a model, like the ActiveRecord's way Model.all . I'm new to ORM2 and it seems pretty obvious, but I don't have a clue...
I think this does it:
var Blah = db.models.blah;
Blah.all(function(err, blahs){
})
Looking at the code Model.js which defines the methods for the Model (Blah above) has the following line:
model.all = model.find;
So I assume Blah.find() would work as well. The methods used in the model instances are defined in the file Instance.js. The documentation isn't super, but I have been happy with the project so far, and likely can help out if you have questions

Selecting from a View in Subsonic causes an error!

Sorry if this seems a silly questions but can you select from a view in subsonic?
I have a view called fixturesinfo and I am running this subsonic query:
FixturesInfoCollection fixtures = new SubSonic.Select().From<FixturesInfo>()
.Where(FixturesInfo.Columns.FixtureDate).IsGreaterThan(DateTime.Now.AddMonths(-3))
.ExecuteAsCollection<FixturesInfoCollection>();
When I run it I get an error dbo.FixturesInfo.
This happens with all views.
Am I doing something wrong here?
Thanks Bex
Worked it out..
I am using two database connection string and it appears as it was a generic select it wasn't picking the right one.
Instead if I do this:
FixturesInfoCollection fixtures =new FixturesInfoCollection()
.Where(FixturesInfo.Columns.FixtureDate,
Comparison.GreaterThan, DateTime.Now)
.OrderByAsc(FixturesInfo.Columns.FixtureDate).Load();
It works

subsonic query problem

I'm using subsonic 2.2 in an app. I'm running a little complicated query in I have used both "And" and "Or" for a field, I'm little confused about how it is going to be translated into sql statement
MytableCollection col = DB.Select().From("mytable").Where("prop1").IsEqualTo(obj.prop1)
.And("prop2").IsEqualTo(obj.prop2)
.And("prop3").IsEqualTo(obj.prop3)
.Or("prop1").IsEqualTo(1)
.ExecuteAsCollection<MytableCollection>();
I want to perform query like this.
select * from mytable where (prop1=obj.prop1 or prop1=1) and prop2=obj.prop2 and prop23=obj.prop3
As Andra says you can use AndExpression. This should do what you want:
MytableCollection col = DB.Select().From(Mytable.Schema)
.Where(Mytable.Columns.Prop2).IsEqualTo(obj.prop2)
.And(Mytable.Columns.Prop3).IsEqualTo(obj.prop3)
.AndExpression(Mytable.Columns.Prop1).IsEqualTo(obj.prop1)
.Or(Mytable.Columns.Prop1).IsEqualTo(1)
.ExecuteAsCollection<MytableCollection>();
N.B. using MyTable.Schema and MyTable.Columns will catch a lot of issues at compile time if you rename tablees and will save errors caused by mistyping
Something that is REALLY useful to know about is also the following two methods to call in your query building:
.OpenExpression()
and
.CloseExpression()
Mix those bad buoys and you have a lot better control over knowing where things start and finish
you can use expression in subsonic 2.2.
MytableCollection col = new Select(Mytable.Schema)
.WhereExpression("prop1").IsEqualTo(obj.prop1).Or("prop1").IsEqualTo(1)
.AndExpression("prop2").IsEqualTo(obj.prop2)
.AndExpression("prop3").IsEqualTo(obj.prop3)
.ExecuteAsCollection<MytableCollection>();

Resources